jQuery nextAll()
The jQuery nextAll()
method retrieves all the elements that come after the selected element.
Syntax
$(selector).nextAll(filter)
selector
: Required. Specifies the element to retrieve the next siblings from.filter
: Optional. Specifies a selector to filter the next siblings.
Use
The nextAll()
method is primarily used to retrieve all the following siblings of an element based on a given filter.
Example
Suppose we have a simple HTML list as follows:
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li class="active">Item 4</li>
<li>Item 5</li>
</ul>
We can use the nextAll()
method to select all the elements that come after the active <li>
element:
$("li.active").nextAll().css("background-color", "yellow");