JavaScript document.createTextNode() Method
You are Here:
JavaScript document.createTextNode() Method
The document.createTextNode()
method creates a new Text node.
Note: This method can be used to escape HTML characters.
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<body>
<script>
var text = document.createTextNode("<p>This is Text</p>");
document.body.appendChild(text);
</script>
</body>
</html>
Syntax
document.createTextNode(data)
Parameter Values
Value | Type | Explanation |
---|---|---|
data | Required | A string containing the data to be put in the text node. |
Replacing the Text in the <h1> tag.
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<body>
<h1>Heading</h1>
<script>
var x = document.getElementsByTagName("h1")[0];
var t = document.createTextNode("This is Text");
x.appendChild(t);
</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.