document.createTextNode

  • Revision slug: DOM/document.createTextNode
  • Revision title: document.createTextNode
  • Revision id: 10369
  • Created:
  • Creator: Matej Lednar
  • Is current revision? No
  • Comment no wording changes

Revision Content

{{ DomRef() }}

Summary

Creates a new Text node.

Syntax

var text = document.createTextNode(data);

Parameters

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

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>

Specification

createTextNode

{{ languages( { "fr": "fr/DOM/document.createTextNode", "ko": "ko/DOM/document.createTextNode", "pl": "pl/DOM/document.createTextNode" } ) }}

Revision Source

<p>{{ DomRef() }}</p>
<h3 name="Summary">Summary</h3>
<p>Creates a new Text node.</p>
<h3 name="Syntax">Syntax</h3>
<pre class="eval"><em>var text</em> = document.createTextNode(<em>data</em>);
</pre>
<h3 name="Parameters">Parameters</h3>
<ul> <li><code>text</code> is a Text node.</li> <li><code>data</code> is a string containing the data to be put in the text node.</li>
</ul>
<h3 name="Example">Example</h3>
<pre>&lt;html&gt;
&lt;head&gt;
&lt;title&gt;createTextNode example&lt;/title&gt;

&lt;script type="text/javascript"&gt;

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

&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;div style="border: 1px solid red"&gt;
&lt;p id="p1"&gt;First line of paragraph.&lt;br /&gt;&lt;/p&gt;
&lt;/div&gt;&lt;br /&gt;

&lt;button onclick="addTextNode();"&gt;add another textNode.&lt;/button&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre>
<h3 name="Specification">Specification</h3>
<p><a class="external" href="http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1975348127">createTextNode </a></p>
<p>{{ languages( { "fr": "fr/DOM/document.createTextNode", "ko": "ko/DOM/document.createTextNode", "pl": "pl/DOM/document.createTextNode" } ) }}</p>
Revert to this revision