Traversing up and down DOM nodes


show more Traversing up and down DOM nodes provides you with in-depth training on Developer. Taught by Ray Villalobos as part of the JavaScript: Enhancing the DOM show less
please wait ...

Traversing up and down DOM nodes

As we saw in the previous chapter, Java Script has a number of DOM selection functions. However, once you have the element it's important to understand how to move up and down the node tree. Every node in the DOM has a series of properties that you can use to move up and down the node list. So for example, you can use parent node to go up a level and get to the parent of an existing node. Child node is an array of all the children of the current nodes. So any sub-nodes of the current node. You can use firstChild and lastChild as a property and acts as the first and last element of the children of the current node.

Finally, you can also use previousSibbling and nextSibbling to move within elements that have the same parent. So, let me show you how this works. Here's our document and I'm going to go into the developer tools, then hit the Esc key to get into the console. So, first off I'm going to assign a node and our DOM to a variable. So, I'll say varia...

Traversing up and down DOM nodes
Video duration: 4m 40s 2h 3m Intermediate

Viewers:

Traversing up and down DOM nodes provides you with in-depth training on Developer. Taught by Ray Villalobos as part of the JavaScript: Enhancing the DOM

Subjects:
Developer Web
Software:
HTML JavaScript
Author:
please wait ...