Descendant Selector (“ancestor descendant”) in JQuery



version added: 1.0jQuery(‘ancestor descendant’)

  • ancestor
    Any valid selector.
    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.

<!DOCTYPE html>

  body { font-size:14px; }
  form { border:2px green solid; padding:2px; margin:0; 
         background:#efe; }
  div { color:red; }
  fieldset { margin:1px; padding:3px; }
  <script src="/scripts/jquery-1.4.js"></script>
    <div>Form is surrounded by the green outline</div>
    <input name="name" />

      <input name="newsletter" />

  Sibling to form: <input name="none" />
<script>$("form input").css("border", "2px dotted blue");</script>

Leave a Reply

Your email address will not be published. Required fields are marked *