158 of 264 menu

lastChild property

The lastChild property stores the last element node. If the element has no children, then null is returned.

Syntax

element.lastChild;

Example

Let's obtain a text of the last element node:

<div id="parent">text<p>parag</p><!--com--></div> let parent = document.querySelector('#parent'); let text = parent.lastChild.textContent; console.log(text);

The code execution result:

'com'

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