splitText method
Divides a text node at the specified index.
![]() |
Syntax
var retval = TextNode.splitText(offset);Parameters
- offset [in, optional]
-
Type: Integer
A Integer that specifies the index of the string that indicates where the separation occurs. If a value is not provided, a new text node with no value is created.
Return value
Type: IHTMLDOMNode
Returns a text node object.
Standards information
Remarks
The text node that invokes the splitText method has a nodeValue equal to the substring of the value, from zero to offset. The new text node has a nodeValue of the substring of the original value, from the specified index to the value length. Text node integrity is not preserved when the document is saved or persisted.
Examples
This example uses the splitText method to divide a text node in half in a ul object. When the text node splits, the createElement method creates a new li object. The appendChild method appends the new li element and the split text node to the ul object.
<SCRIPT>
function fnSplitNode(){
var oNode=oList.firstChild.childNodes(0);
var oNewNode=document.createElement("LI");
var oSplitNode = oNode.splitText(oNode.nodeValue.length/2);
oList.appendChild(oNewNode);
oNewNode.appendChild(oSplitNode);
}
</SCRIPT>
<UL onclick="fnSplitNode()" id="oList">
<LI>This is a list item.
</UL>
See also
Send comments about this topic to Microsoft
Build date: 11/27/2012
