Properties
- Data
- Length
Methods
- appendData(String)
- deleteData(start, length)
- insertData(start, string)
- replaceData(start, length, string)
- splitText(start)
- substringData(start, length)
Length
Length property is used to access the length of Text which indicates the number of characters it contains.
Syntax:- TextNode.length
Data
Data property is used to set or return the value of a text node and comment node objects.
Syntax: –
Sets
TextNode.data = value
Returns
TextNode.data
Ex:- TextNode.data = “Hello DevOpsSchool”;
appendData(String)
This method is used to append the passed string to the end of the text node and comment node.
Syntax: –
TextNode.appendData(String);
Ex: –
TextNode.appendData(“Hello DevOpsSchool”);
deleteData(start, length)
This method is used to delete or remove text content from a text node and comment node. It deletes the specified length of characters starting from index defined in start.
Syntax:-
TextNode.deleteData(start, length);
Ex: –
TextNode.deleteData(0, 5);
insertData(start, string)
This method is used to insert text content to text node and comment node. It inserts the value in string, starting at the character index specified in start.
Syntax:-
TextNode.insertData(start, string)
Ex: –
TextNode.insertData(3, “Hello”)
replaceData(start, length, string)
This method is used to replace text content of text node and comment node. It inserts the value in string, starting at the character index specified in start.
Syntax:-
TextNode.replaceData(start, length, string)
Ex: –
TextNode.replaceData(0, 4, “Hello”)
splitText(start)
The splitText(start) method breaks the Text node into two nodes at the specified start index, keeping both nodes in the tree as siblings. It returns right side of the split in a new text node and leaves the left side in the original.
Syntax: –
var rightSide = TextNode.splitText(start)
Ex: –
var rightSide = TextNode.splitText(5)
substringData(start, length)
It returns the part of the current element’s (TextNode and CommentNode) text content from the specified position with the specified length.
Syntax:-
TextNode.substringData(start, length)
Ex: –
TextNode.substringData(2, 5);