Descendant Selector (“ancestor descendant”)

descendant selector

version added: 1.0jQuery('ancestor descendant')

  • ancestor
    任何有效的选择器。
    descendant
    一个用来筛选后代元素的选择器。

描述: 选择所有给定的祖先的后代元素。

一个元素的后代可能是该元素的一个孩子,孙子,曾孙等。

Example:

Finds all input descendants of forms.

<!DOCTYPE html>
<html>
<head>
  <style>

  body { font-size:14px; }
  form { border:2px green solid; padding:2px; margin:0; 
         background:#efe; }
  div { color:red; }
  fieldset { margin:1px; padding:3px; }
  </style>
  <script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
  <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" />
<script>$("form input").css("border", "2px dotted blue");</script>

</body>
</html>

Demo:

jQuery 1.6 API 中文版Clove整理、修订