“This is the 24th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021.”

The Text type

The Text node is represented by the Text type and contains literal plain Text, or possibly escaped HTML characters, but no HTML code.

Nodes of type Text have the following characteristics:

  • nodeType = 3
  • nodeName = “#text”
  • NodeValue is the text on the node
  • ParentNode is an Element object
  • There will be no child nodes

The Text contained in the Text node can be accessed using either the nodeValue attribute or the data attribute, meaning that both attributes point to the same location

The span is obtained by id. The span. ChildNodes command queries the current set of childNodes

The Text node provides these methods for Text manipulation

appendData(text)

Add text to the end of the node

deleteData(offset, count)

Remove count characters from position offset

insertData(offset, text)

Insert text at position offset

replaceData(offset, count, text)

Replace the text from position offset to offset + count with text

splitText(offset)

The offset position splits the current text node into two text nodes

A query to sp.childnodes shows that there are now 2 childNodes of type text

substringData(offset, count)

Extract the text from position offset to offset + count.

This method simply returns the truncated Text of a node of type Text and does not modify the Text data on the DOM


If the label is blank, that is, there is no text in the middle of the label, then the label has no text node

In this case, the tag will have a single text node (as in most of the operations above). You can also modify the attributes directly using.nodeValue to immediately change the text displayed on the HTML