jQuery siblings()Method
Example
Return all sibling elements of each <li> element with class name "start":
$(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 Yourself »
Definition and Usage
The siblings() method returns all sibling elements of the selected elements.
Sibling elements are elements that share the same parent.
DOM tree:This method traverses forwards and backwards along the sibling elements of DOM elements.
Tip:Please useprev()ornext()method to narrow the search scope to only the previous sibling elements or the next sibling elements.
Syntax
$(selector).siblings(filter)
| Parameter | Description |
|---|---|
| filter | Optional. Specifies a selector expression to narrow the search range of sibling elements. |
More Examples
Narrow the search scope
How to use two parameters to filter the search for sibling elements.
Select all sibling <p> elements of each <div> element.
How to narrow the search for all sibling <p> elements of each <div> element.
Other Extensions
jQuery \nTraversal Methods