Definition and Usage..
The createTextNode() method creates a Text Node with the specified text.
Tip: Use the createElement() method to create an Element Node with the specified name.
Tip: After the Text Node is created, use the element.appendChild() or element.insertBefore() method to append it to an element
Syntax: document.createTextNode(text)
Different way to how to createTextNode() Method declare in program.
<!DOCTYPE html>
<html>
<body>
<p>Click the button to create a Text Node.</p>
<button onclick="TextNode()">Create TextNode in Body tag</button>
<button onclick="TextNodeElmnt()">Create TextNode in H1 tag</button>
<script>
function TextNode() {
var t = document.createTextNode("Hello World");
document.body.appendChild(t);
}
function TextNodeElmnt() {
var h = document.createElement("H1");
var t = document.createTextNode("Hello World");
h.appendChild(t);
document.body.appendChild(h);
//h.innerHTML=""; define and not used append() method
}
</script>
</body>
</html>
<html>
<body>
<p>Click the button to create a Text Node.</p>
<button onclick="TextNode()">Create TextNode in Body tag</button>
<button onclick="TextNodeElmnt()">Create TextNode in H1 tag</button>
<script>
function TextNode() {
var t = document.createTextNode("Hello World");
document.body.appendChild(t);
}
function TextNodeElmnt() {
var h = document.createElement("H1");
var t = document.createTextNode("Hello World");
h.appendChild(t);
document.body.appendChild(h);
//h.innerHTML=""; define and not used append() method
}
</script>
</body>
</html>
Comments
Post a Comment