javascript-Node Attribute resolution
Each component in the dom,html document is a node. HTML is the root node.
The DOM (Document Object Model) is defined as:
The entire document is a document node
Each HTML tag is an element node
Text that is contained in an HTML element is a text node
Each HTML attribute is an attribute node
Comments belong to note nodes
First, how to get the node reference
1. How the node reference was previously obtained:
getElementById ()
Getelementbytagname ()
Getelementbyname ()
Disadvantage:
1. Wasting memory
2. Not strong logic
2. Obtain a reference to a node through the node relationship property:
Object. parentnode get a reference to the parent node
Object. ChildNodes gets the collection of child nodes
Object. FirstChild get the first child node
Object. LastChild get the last child node
Object. nextSibling get a reference to the next sibling node
Object. PreviousSibling get a reference to the previous sibling node
Disadvantage: Poor compatibility.
Second, node information (attributes)
Node type node name node value
NodeType (value) NodeName NodeValue
Element node 1 label name null
Attribute Node 2 Property Name property value
Text Node 3 #text text
Note Node 8 #comment The text of the note,
Document node 9 #document null
Javascript-Node Properties detailed