Accessing Nodes in DOM
There are two ways to get at a node in DOM. You can either walk the tree or access the node directly by name. In practice, a document is accessed using a combination of both methods.
Walking the Tree
To walk DOM tree, start anywhere in the tree and use the following methods of DOM node interface:
parentNode(). This method will access the parent node.
firstChild(). This method will access the first child of the node. If there is no such node, null is returned.
nextSibling(). This method accesses the next sibling node. If no such node exists, null is returned.
previousSibling(). This method accesses the previous sibling node. If no such node exists, null is returned.
It is easy to see how you can move throughout ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access