ancestor descendant

选择给定元素的所有后代元素。

一个元素的后代元素可以是该元素的儿子元素,孙子元素或重孙子元素等等。

示例:

查找表单元素的所有 input 后代元素。

<!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="jquery.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>

演示: