jQuery API jQuery API 中英文对照版 - jQuery在线查询手册
children(expr)
children(expr)

取得一个包含匹配的元素集合中每一个元素的所有唯一子元素的元素集合。 可以用可选的表达式进行筛选。

返回值:jQuery

参数:

  • expr (String): (可选) 用于筛选子元素的表达式
 
示例:

找到每个div的所有子元素。

$("div").children()

HTML 代码:

<p>Hello</p><div><span>Hello   Again</span></div><p>And Again</p>

结果:

[ <span>Hello Again</span> ] 
示例:

找到每个div的所有子元素中带有类名为selected的元素。

$("div").children(".selected") 

HTML 代码:

<div><span>Hello</span><p   class="selected">Hello Again</p><p>And   Again</p></div>

结果:

[ <p class="selected">Hello Again</p> ]

 

children( expr )

Get a set of elements containing all of the unique children of each of the matched set of elements.

This set can be filtered with an optional expression that will cause only elements matching the selector to be collected.

Return value: jQuery
Parameters:

  • expr (String): (optional) An expression to filter the child Elements with
 

Example:

Find all children of each div.

 $("div").children()  
Before:
 <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>  
Result:
 [ <span>Hello Again</span> ]  

Example:

Find all children with a class "selected" of each div.

 $("div").children(".selected")  
Before:
 <div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>  
Result:
 [ <p class="selected">Hello Again</p> ]