160 of 264 menu

nextElementSibling property

The nextElementSibling property contains the next element in the same parent. If there is no such element, null is returned.

Syntax

element.nextElementSibling;

Example

The element #elem is given. Let's display the text of his neighbor from below:

<p id="elem">elem</p> <p>sibling</p> let elem = document.querySelector('#elem'); let text = elem.nextElementSibling.textContent; console.log(text);

The code execution result:

'sibling'

Example

If there is no bottom neighbor or it is located not in the parent of our element, null is also returned:

<div> <p id="elem">elem</p> </div> <p>sibling</p> let elem = document.querySelector('#elem'); console.log(elem.nextElementSibling);

The code execution result:

null

See also

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