Latest web development tutorials

jQuery siblings () method

jQuery traversal methods jQuery traversal methods

Examples

Returns all sibling elements with class name of "start" for each <li> element:

$(document).ready(function(){
$("li.start").siblings().css({"color":"red","border":"2px solid red"});
});

result:

    ul (parent)
  • li (sibling)
  • li (sibling)
  • li (sibling with class name "start")
  • li (sibling)
  • li (sibling)

try it"

Definition and Usage

siblings () method returns the selected element all siblings.

Sibling elements are elements that share the same parent element.

DOM tree: This method forward and backward along the traverse siblings DOM elements.

Tip: Use the prev () or next () method to narrow down the search just before and after a sibling or a sibling element element.


grammar

$(selector).siblings( filter )

参数 描述
filter 可选。规定缩小搜索同级元素范围的选择器表达式。

Examples

More examples

Narrow your search
How to use two parameters to filter the search for similar elements.

Select each <div> element in all sibling <p> element
How to narrow the search range for all sibling <p> element for each <div> element.


jQuery traversal methods jQuery traversal methods