The next method

The next method returns the element that comes after the given one within one parent.

Syntax

Getting an immediate neighbor:

javascript.next();

You can also select an immediate neighbor only if it satisfies a given selector:

javascript.next(selector);

Example

Let's find the element #test and set the text '!' to its bottom neighbor using the html method:

html<p>text</p>
<p>text</p>
<p id="test">text</p>
<p>text</p>
<p>text</p>
javascript$('#test').next().html('!');

HTML the code will look like this:

html<p>text</p>
<p>text</p>
<p id="test">text</p>
<p>!</p>
<p>text</p>

See also

  • method prev,
    which allows the element's neighbor to be above
  • method nextAll,
    which returns elements that are after the given one within the same parent
  • 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
  • JavaScript property nextElementSibling,
    which contains the next element located in the same parent