splitText method (TextNode)
The index specifies the character position in the contents of the current TextNode where the split occurs. The first part will be the new content of the current TextNode and a new TextNode object is created from the second part. The new TextNode object is inserted into the document hierarchy as the next sibling of the current TextNode object.
If you want to join adjacent text nodes into a single text node, use the normalize method.
You can find the related objects in the Supported by objects section below.
Required in Firefox and Opera, optional in Internet Explorer, Google Chrome and Safari.
Zero-based integer that specifies the character position in the contents of the current TextNode at which the split occurs.
The default is zero in Internet Explorer, Google Chrome and Safari. Splitting at the last position is allowed in all browsers, but it is buggy in Internet Explorer (the new TextNode is not inserted into the document hierarchy and its data is undefined, not an empty string).
Returns the TextNode object created from the second part.
Example HTML code 1:
This example illustrates the use of the splitText method:
Did you find this example helpful?
User Contributed Comments