170 of 264 menu

createTextNode method

The createTextNode method creates a new text node. In the parameter, the method receives the data to be inserted into the new text node.

Syntax

let text = document.createTextNode(data);

Example

Let's make a new text node in a document:

<div id="parent"> <p>text1</p> <p>text2</p> </div> let parent = document.getElementById('parent'); let text = document.createTextNode('text3'); parent.appendChild(text);

The code execution result:

<div id="parent"> <p>text1</p> <p>text2</p> text3 </div>

See also

  • the createElement method
    that can be used to create a new element
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