Javascript DOM HTML Document createTextNode() Method

Introduction

Create a <h1> element with some text:

Click the button to create a h1 element with some text.

View in separate window

<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Test</button>

<script>
function myFunction() {/*from www.  j  a v  a 2  s. c  o  m*/
  var h = document.createElement("H1");
  var t = document.createTextNode("Hello World");
  h.appendChild(t);
  document.body.appendChild(h);
}
</script>

</body>
</html>

The createTextNode() method creates a Text Node with the specified text.

document.createTextNode(text);

Parameter Values

Parameter Type Description
text String Required. The text of the Text node

The createTextNode() method returns a Text Node object with the created Text Node.




PreviousNext

Related