49 of 119 menu

The nextAll method

The nextAll method returns all elements that are after the given one within a single parent.

Syntax

Getting all neighbors below:

$(selector).nextAll();

You can also filter neighbors by a given selector:

$(element).nextAll(selector);

Example

Let's find the element #test and set the text '!' to all its neighbors below using the html method:

<p>outside</p> <div> <p>inside</p> <p>inside</p> <p id="test">inside</p> <p>inside</p> <p>inside</p> </div> <p>outside</p> $('#test').nextAll().html('!');

HTML the code will look like this:

<p>outside</p> <div> <p>inside</p> <p>inside</p> <p id="test">inside</p> <p>!</p> <p>!</p> </div> <p>outside</p>

See also

  • method prevAll,
    which returns the elements that come before the given one within the same parent
  • method next,
    which allows the element's neighbor below
  • method nextUntil,
    which returns the elements after the given one
  • method siblings,
    which allows you to get the neighbors of an element within one parent
enru