184 of 264 menu

The data property

The data property allows you to read the contents of an element's text node, including commented out text.

Syntax

element.data;

Example

Let's output the text of the first child element using the data property:

<body> text1 <!--com1--> text2 <!--com2--> </body> let elem = document.body.firstChild; console.log(elem.data);

The code execution result:

'text1'

Example

And now let's display the comment of the first child element:

<body> text1 <!--com1--> text2 <!--com2--> </body> let elem = document.body.firstChild; let comment = elem.nextSibling; console.log(comment.data);

The code execution result:

'com1'

See also

  • the nodeValue method
    that sets a node value
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