splitText (DOMText - JavaScript)
Splits a text node keeping the first part and returning the second part.
Defined in
DOMTextSyntax
Parameters | Description |
---|---|
offset |
The first character of the second part of the split where 0 is the first character of the text. The offset must be a valid number between 0 and the last offset in the text. |
Return value | Description |
---|---|
DOMText |
The second part of the text. |
Usage
This method removes from the current node the second part of the text.This method returns the second part of the text but does not place it in the DOM. You must, for example, append the new text node with appendChild in DOMNode.
Examples
This button creates a document with a hierarchy of elements with a text node then splits the text node at offset 3 and appends the split text as a second text node.var doc = database.createNewDocument();
var dom = doc.getDOM();
var schema0 = dom.createElement("schema0");
var element0 = dom.createElement("element0");
var element1 = dom.createElement("element1");
var text0 = dom.createTextNode(requestScope.s);
var text1 = dom.createTextNode(text0.splitText(3).getData());
dom.appendChild(schema0);
schema0.appendChild(element0);
schema0.appendChild(element1);
element0.appendChild(text0);
element1.appendChild(text1);
doc.save()
The XML appears as follows if
requestScope.s
is foobar
:<schema0>
<element0>foo</element0>
<element1>bar</element1>
</schema0>