jQuery siblings() method
Example
Return each with class name "start"
$
(
document
)
.
ready
(
function
(
)
{
$
(
"
li.start
"
)
.
siblings
(
)
.
css
(
{
"
color
"
:
"
red
"
,
"
border
"
:
"
2px solid red
"
}
)
;
}
)
;
Result:
- li (sibling)
- li (sibling)
- li (sibling with class name "start")
- li (sibling)
- li (sibling)
Try it »
Definition and Usage
The siblings() method returns all sibling elements of the selected element.
Sibling elements are elements that share the same parent element.
**DOM Tree:** This method traverses both forward and backward along the sibling elements of the DOM element.
**Tip:** Please use prev() or next() method to narrow down the search to only the previous sibling element or the next sibling element.
Syntax
$(
selector
).siblings(
filter
)
| Parameters | Description |
|---|---|
| filter | Optional. Specifies a selector expression to narrow down the search for sibling elements. |
More examples
Narrow down the search
How to use two parameters to filter the search for sibling elements.
all siblings of the element
Element
How to narrow down the search for each
jQuery Traversal Methods