Visit Mozilla.org

DOM:document.createTextNode

From MDC

« Gecko DOM Reference

Contents

[edit] Summary

Creates a new Text node.

[edit] Syntax

text = document.createTextNode(data) 

[edit] Parameters

  • text is a Text node.
  • data is a string containing the data to be put in the text node.

[edit] Example

<html>
<head>
<title>createTextNode example</title>

<script type="text/javascript">

function addTextNode()
{
var newtext = document.createTextNode(" Some text added dynamically. ");
var para = document.getElementById("p1");
para.appendChild(newtext);
}

</script>
</head>

<body>
<div style="border: 1px solid red">
<p id="p1">First line of paragraph.<br /></p>
</div><br />

<button onclick="addTextNode();">add another textNode.</button>

</body>
</html>

[edit] Specification

createTextNode