jQuery:Selector ancestor descendant

Overview

Select all descendant elements with given ancestor element.

Parameter

ancestorSelectorV1.0

Any valid selector.

descendantSelectorV1.0

A selector to match the element, and it is the descendant of the first selector.

Demo

Description:

To find all input elements in form.

HTML code:
<form>
  <label>Name:</label>
  <input name="name" />
  <fieldset>
      <label>Newsletter:</label>
      <input name="newsletter" />
 </fieldset>
</form>
<input name="none" />
jQuery code:
$("form input")
result:
[ <input name="name" />, <input name="newsletter" /> ]

Leave a Reply

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