Descendant Selector ("ancestor descendant")
Categories: Hierarchy
jQuery('ancestor descendant')
Description: Selects all elements that are descendants of a given ancestor.
-
jQuery('ancestor descendant')
version added: 1.0ancestor Any valid selector.
descendant A selector to filter the descendant elements.
A descendant of an element could be a child, grandchild, great-grandchild, and so on, of that element.
-
Finds all input descendants of forms.
HTML:
<form> <div>Form is surrounded by the green outline</div> <label>Child:</label> <input name="name" /> <fieldset> <label>Grandchild:</label> <input name="newsletter" /> </fieldset> </form> Sibling to form: <input name="none" />
CSS:
body { font-size:14px; } form { border:2px green solid; padding:2px; margin:0; background:#efe; } div { color:red; } fieldset { margin:1px; padding:3px; }
Code:
$("form input").css("border", "2px dotted blue");