A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://webplatform.github.io/docs/dom/Text/splitText below:

splitText ยท WebPlatform Docs

splitText Summary

Divides a text node at the specified index.

Method of dom/Textdom/Text

Syntax
var textNode = textNode.splitText();
Parameters offset
Data-type
String

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 an object of type DOM NodeDOM Node

A text node object.

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.</li>
</ul>
Notes

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.

Related specifications
DOM Level 3 Core
Recommendation
Attributions

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4