jQuery API 返回首页目录 | jQuery API 中英文对照版
next(expr)
next(expr)

取得一个包含匹配的元素集合中每一个元素紧邻的后面同辈元素的元素集合。

这个函数只返回后面那个紧邻的同辈元素,而不是后面所有的同辈元素。 可以用一个可选的表达式进行筛选。

返回值:jQuery

参数:

  • expr (String): (可选) 用于筛选后面同辈元素的表达式
 
示例:

找到每个段落的后面紧邻的同辈元素。

$("p").next() 

HTML 代码:

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

结果:

[ <p>Hello Again</p>, <div><span>And   Again</span></div> ] 
示例:

找到每个段落的后面紧邻的同辈元素中类名为selected的元素。

$("p").next(".selected") 

HTML 代码:

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

结果:

[ <p class="selected">Hello Again</p>   ] 
 
next( expr )

Get a set of elements containing the unique next siblings of each of the matched set of elements.

It only returns the very next sibling for each element, not all next siblings.

You may provide an optional expression to filter the match.

Return value: jQuery
Parameters:

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

Example:

Find the very next sibling of each paragraph.

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


Example:

Find the very next sibling of each paragraph that has a class "selected".

 $("p").next(".selected")  
Before:
 <p>Hello</p><p class="selected">Hello Again</p><div><span>And Again</span></div>  

Result:

 [ <p class="selected">Hello Again</p> ]  
相关链接
asp之家 | jQuery官方网站 | jQuery中文网 | 电子书作者网站 | 电子书作者blog