From the course: JavaScript: Enhancing the DOM (2013)
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Traversing up and down DOM nodes
From the course: JavaScript: Enhancing the DOM (2013)
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 variable my node is going to be equal…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
(Locked)
Selecting elements with getElementById4m 10s
-
(Locked)
Choosing elements by HTML tag3m 20s
-
(Locked)
Isolating elements by class name3m 12s
-
(Locked)
Querying CSS to select elements4m 54s
-
(Locked)
Working with named form elements3m 39s
-
(Locked)
Understanding nodeType, nodeName, and nodeValue4m 30s
-
(Locked)
Traversing up and down DOM nodes4m 40s
-
(Locked)
Targeting node elements2m 44s
-
(Locked)
-
-
-
-