Selecting Elements by Hierarchy Positioning

$("div span");   //selects <span> elements with a <div> ancestor $("div.menu > span");   //selects <span> elements whose immediate parent   //is a <div> with class="menu" $("label + input.textItem");   //selects <input> elements with class="textItem" that   //are immediately preceded by a <label> $("#menu ~ div");   //selects all <div> elements that are siblings of   //the element with id="menu"

An important set of jQuery selectors is the hierarchy selectors. These selectors allow you to select HTML elements based on the DOM hierarchy. This allows you to write dynamic code that is more content aware by only selecting elements based on parents, children, or other elements ...

Get jQuery and JavaScript Phrasebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.