JavaScript node.textContent Property

You are Here:

JavaScript node.textContent Property

The node.textContent property gets or sets the text content of the specified node, and all its descendants.

Note: This property is read/write.

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <p>In this example, there will be no difference between "innerText" and "textContent".</p> <p>Text without <b>spacing</b>.</p> <button onclick="myinnerHTML()">innerHTML</button> <button onclick="myinnerText()">innerText</button> <button onclick="mytextContent()">textContent</button> <script> var y = document.getElementsByTagName("p")[1]; function myinnerHTML(){ alert(y.innerHTML); } function myinnerText(){ alert(y.innerText); } function mytextContent(){ alert(y.textContent); } </script> </body> </html>

Syntax

node.textContent

Return Value

ValueExplanation
StringReturns the textual content of an element and all its descendants.

innerHTML vs innerText vs textContent

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <p>This example will demonstrate the difference between "innerHTML" vs "innerText" vs "textContent".</p> <p>Text with <b>spacing</b>.</p> <button onclick="myinnerHTML()">innerHTML</button> <button onclick="myinnerText()">innerText</button> <button onclick="mytextContent()">textContent</button> <script> var y = document.getElementsByTagName("p")[1]; function myinnerHTML(){ alert(y.innerHTML); } function myinnerText(){ alert(y.innerText); } function mytextContent(){ alert(y.textContent); } </script> </body> </html>

Reminder

Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author