Skip to content Skip to sidebar Skip to footer

Selecting A Nested Element By Id Or Class With Jquery

I'm a bit confused how jquery searches through the DOM. Does it select from the root node, similar to XPath / selector, or from the current no matter where they are, similar to XP

Solution 1:

Is there a way to select from the root any element anywhere in the DOM?

So long as you start from document., the standard javascript methods all select from the root:

  • document.getElementById('');
  • document.getElementsByClassName('');
  • document.getElementsByTagName('');
  • document.querySelector('');
  • document.querySelectorAll('');

Solution 2:

Yes the selectors work across the DOM (http://api.jquery.com/category/selectors/)

The fiddles supplied in the comments work, have you checked your console for errors, maybe the javascript isn't running completely.

Post a Comment for "Selecting A Nested Element By Id Or Class With Jquery"