jQuery nextUntil() method
Example
Return the two with class names "start" and "stop"
$
(
document
)
.
ready
(
function
(
)
{
$
(
"
li.start
"
)
.
nextUntil
(
"
li.stop
"
)
.
css
(
{
"
color
"
:
"
red
"
,
"
border
"
:
"
2px solid red
"
}
)
;
}
)
;
Result:
- li (sibling)
- li (sibling)
- li (sibling with class name "start")
- li (sibling)
- li (sibling)
- li (sibling)
- li (sibling with class name "stop")
Try it »
Definition and Usage
The nextUntil() method returns selector The difference between stop all sibling elements after each element between the two.
Sibling elements are elements that share the same parent element.
**DOM Tree:** This method traverses forward along the sibling elements of the DOM element.
**Note:** If both parameters are empty, this method returns all sibling elements after the element (same as nextAll() method).
Related methods:
- next() - returns the next sibling element of the selected element
- nextAll() - returns all sibling elements after the selected element
Syntax
$(
selector
).nextUntil(
stop,filter
)
| Parameters | Description |
|---|---|
| stop | Optional. A selector expression, element, or jQuery object indicating where to stop searching for matching sibling elements after the element. |
| filter | Optional. Specifies a selector expression to narrow down the search for sibling elements between selector The difference between stop the two. |
**注意:**如需返回多个同级元素,请使用逗号分隔每个表达式。 |
More examples
Narrow down the search
Use two parameters to filter the search for sibling elements after each element between the two parameters.
Return multiple sibling elements
How to return multiple sibling elements between two parameters.
DOM
Use a DOM element instead of a selector to return all sibling elements between two given parameters.
Using a DOM with two parameters
Use a DOM with two parameters instead of a selector to filter the search for sibling elements after each element between the two parameters.
jQuery Traversal Methods