Introduction to nodeName, nodeValue and nodeType nodes

nodeName

  • element node  nodeName is the label name (uppercase)
  • The attribute node  nodeName is the attribute name
  • Text nodes  nodeName are always #text
  • The document node  nodeName is always #document

Note: The tag name of the XML element contained in nodeName is always uppercase

  • For text nodes, nodeValue the attribute contains text.
  • For property nodes, nodeValue properties contain property values.
  • For document nodes and element nodes, nodeValue the value of the attribute is always  null.

nodeValue

For text nodes, the nodeValue property contains the text.

For attribute nodes, the nodeValue attribute contains the attribute value.

The nodeValue property is not available for document nodes and element nodes.

nodeType

nodeType is an HTML DOM property in JavaScript. The nodeType attribute returns the node type of the selected node, which allows us to know and distinguish each node in the document.

All node types in JavaScript inherit from the Node type, so all node types share the same basic properties and methods. Each node has a nodeType property, used to indicate the type of node.

The nodeType property will return 1 if the node is an element node.

The nodeType property will return 2 if the node is an attribute node.

The most important node types are:

 --element type node type:

 element element 1

 attribute attr 2

 text text 3

 Comments 8

 Documentation document 9

Documentation:

Node.nodeType - Web API interface reference | MDN

Guess you like

Origin blog.csdn.net/weixin_48927323/article/details/127051085