jQuery nextAll()Method

jQuery 遍历方法jQuery Traversal Methods

Example

Return all sibling elements after each <li> element with class name "start":

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

Result:

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

Try it Yourself »

Definition and Usage

The nextAll() method returns all sibling elements after the selected element.

Sibling elements are elements that share the same parent element.

DOM tree:This method traverses forward along the sibling elements of DOM elements.

Related Methods:

  • next()- Returns the next sibling of the selected element
  • nextUntil()- Returns all sibling elements after each element between two given parameters

Syntax

$(selector).nextAll(filter)

Parameter Description
filter Optional. Specifies a selector expression to narrow down the range of sibling elements after the selected element.

Note:If you need to return multiple sibling elements, use a comma to separate each expression.

实例

More Examples

Narrow down the search
How to filter the search for sibling elements after an element.

Return multiple sibling elements
How to use the filter parameter to return all sibling elements of the <h2> elements with class names "1", "2", and "3".

Select all sibling elements after the <p> element
How to select all sibling elements after the <p> element.

Select all sibling <p> elements after <div>
How to select all sibling <p> elements after each <div> element.


jQuery 遍历方法jQuery Traversal Methods

Other Extensions