The nextAll method

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

Syntax

Getting all neighbors below:

javascript$(selector).nextAll();

You can also filter neighbors by a given selector:

javascript$(element).nextAll(selector);

Example

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

html<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>
javascript$('#test').nextAll().html('!');

HTML the code will look like this:

html<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