splitText Method

MS Office DHTML, HTML & CSS

splitText Method


Divides a text node at the specified index.

Syntax

oSplitNode = TextNode.splitText(iIndex)

Parameters

iIndexOptional. 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

Returns a text node object.

Remarks

The text node that invokes the splitText method has a nodeValue equal to the substring of the value, from 0 to iIndex. 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.

Example

Sample Code

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()">
<LI>This is a list item.
</UL>

Applies To

[ Object Name ]
PlatformVersion
Win16:
Win32:
Mac:
Unix:
WinCE:
Version data is listed when the mouse hovers over a link, or the link has focus.
TextNode

See Also

createElement


Back to topBack to top

Did you find this topic useful? Suggestions for other topics? write us!Internet Link

© 1999 microsoft corporation. all rights reserved. terms of useInternet Link.