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.

Targeting node elements

Targeting node elements

From the course: JavaScript: Enhancing the DOM (2013)

Start my 1-month free trial

Targeting node elements

In the last movie, we talked about basic access properties for node elements and the problem with traversing the DOM nodes using child nodes. Sometimes you get text elements that are just carriage returns. Some browsers support a better way of selecting elements. So, for example, you can use the property called first element child, and that gives you the first child only if it's an element. Like a tag. So, it would ignore any comment or text nodes. You can also use, of course, last element child and children. Which gives you only children that are elements. Of course, you can also use previous element sibling and next element sibling that's the equivalent of the previous sibling and next sibling. Now, before you get too excited about this, this has really lousy browser support. So, if you go to this page and you take a look at this right here, it's showing you that its available in IE 9 but not in some versions of Firefox. So, it's something good to use for newer browser support but…

Contents