This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

data

Summary

Sets or gets a node’s character data.

Property of dom/CharacterDatadom/CharacterData

Syntax

var text = textualNode.html/elements/data;
textualNode.html/elements/data = newText;

Return Value

Returns an object of type StringString

The value of the text node.

Examples

//create text node
var phrase = document.createTextNode ("A flawed plan today is better than a perfect plan tomorrow.");
//report contents
alert(phrase.data);
//modify contents
phrase.data = "Any plan is better than no plan at all.";
//report contents
alert(phrase.data);

This example uses the data property to change the value of a text node.

<script>
function fnChangeValue(){
   var oNode = oList.firstChild.childNodes(0);
   var oNewText = document.createTextNode();
   oNewText.data="Create Data";
   oNode.replaceNode(oNewText);
   oNode.data = "New Node Value";
}
</script>
<ul id="oList" onclick="fnChangeValue()">
<li>Start Here</li>
</ul>

Related specifications

DOM Level 1
Recommendation

Attributions