HTML | DOM textContent Property
The textContent property in HTML is used to set or return the text content of the specified node and all its descendants. This property is very similar to nodeValue property but this property returns the text of all child nodes.
Syntax:
- It is used to set the text of node.
node.textContent = text
- It is used to return the text of node.
node.textContent
Property Value: It contains single value text which contains node the node content.
Example 1:
<!DOCTYPE html> <html> <head> <title> HTML DOM textContent Property </title> </head> <body> <h1>GeeksforGeeks</h1> <h2>HTML DOM textContent Property</h2> <button id = "geeks" onclick = "MyGeeks()"> Submit </button> <p id = "sudo"></p> <script> function MyGeeks() { var text = document.getElementById("geeks").textContent; document.getElementById("sudo").innerHTML = text; } </script> </body> </html> |
Output:
Before Click on the button:

After Click on the button:

Example 2:
<!DOCTYPE html> <html> <head> <title> HTML DOM textContent Property </title> </head> <body> <h1>GeeksforGeeks</h1> <h2>HTML DOM textContent Property</h2> <p id = "geeks" onclick = "MyGeeks()"> Hello Geeks! </p> <script> function MyGeeks() { document.getElementById("geeks").textContent = "Welcome to GeeksforGeeks!"; } </script> </body> </html> |
Output:
Before Click on the text:

After Click on the text:

Supported Browsers: The browser supported by DOM textContent property are listed below:
- Google Chrome 1.0
- Internet Explorer 9.0
- Firefox
- Opera
- Safari
Recommended Posts:
- HTML | DOM id Property
- HTML | DOM dir Property
- HTML | DOM Map name Property
- HTML | DOM URL Property
- HTML | DOM value Property
- HTML | DOM Bdo dir Property
- HTML | DOM name Property
- HTML | DOM specified Property
- HTML | DOM li value Property
- HTML | DOM activeElement Property
- HTML | DOM Object name Property
- HTML | DOM title Property
- HTML | DOM IFrame name Property
- HTML | DOM offsetHeight Property
- HTML | DOM Script src Property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



