JavaScript Document own method: createTextNode()
[this page | pdf | back links]
The createTextNode() method (when applied
to the document object of the JavaScript
DOM) creates
a text node.
It
has the following syntax with the following parameters. It returns an
element object, representing the created element.
document.createTextNode(text)
Parameter
|
Required / Optional
|
Description
|
text
|
Required
|
String specifying the text
in the text node
|
EXAMPLE:
HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head></head>
<body>
Created using JavaScript:<br><br>
<span id="element"></span>
<script>
var x = document.createElement("EM");
var txt = document.createTextNode("italic text");
x.appendChild(txt);
document.getElementById("element").appendChild(x);
</script>
</body>
</html>
|
FUNCTION THAT MAY ASSIST IN TESTING WHETHER FEATURE IS SUPPORTED:
function isSupportedJavaScriptMethodDomCreateTextNode() {
return !!document.createTextNode;
} |
NAVIGATION LINKS
Contents | Prev | Next | JavaScript DOM (and BOM)