jQuery API | jQuery API 中英文对照版 - jQuery在线查询手册 |
siblings(expr) |
siblings(expr)
取得一个包含匹配的元素集合中每一个元素的所有唯一同辈元素的元素集合。 可以用可选的表达式进行筛选。 返回值:jQuery 参数:
找到每个div的所有同辈元素。 $("div").siblings() HTML 代码: <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p> 结果: [ <p>Hello</p>, <p>And Again</p> ] 示例:找到每个div的所有同辈元素中带有类名为selected的元素。 $("div").siblings(".selected") HTML 代码: <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p> 结果: [ <p class="selected">Hello Again</p> ] Get a set of elements containing all of the unique siblings of each of the matched set of elements. Can be filtered with an optional expressions. Return value: jQuery
Example: Find all siblings of each div. $("div").siblings()Before: <p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>Result: [ <p>Hello</p>, <p>And Again</p> ] Example: Find all siblings with a class "selected" of each div. $("div").siblings(".selected")Before: <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p> Result: [ <p class="selected">Hello Again</p> ] |