⊗jqSePNM 79 of 113 menu

jQuery prev and next methods

The prev method can be used to access the top neighbor of a given element, while next can be used to access the bottom neighbor (note that elements are considered neighbors only within the same parent).

Let's take the following paragraphs as an example:

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

Now we find the element #test and put the text '!' to its neighbor above:

$('#test').prev().html('!');

Now let's perform a similar operation with the neighbor below:

$('#test').next().html('!');

Find the first element that immediately precedes the element with class test.

Find the first element that immediately follows the element with class test.

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline