JAVASCRIOPT Dom has three main nodes: element node, attribute node, text node.
The three main methods of acquiring ELEMENT nodes are:
1.document.getelementbyid (); This method gets the node based on the unique ID value of the node.
such as <li id = "Hamigua" > Cantaloupe </li>,document.getelementbyid ("Hamigua");
2.document.getelementbytagname (); This method gets the node based on the label name of the node.
such as <li></li> tags, document.getelementbytagname ("Li");
3.document.getelementbyname (); This method gets the node based on the Name property of the node.
such as <input type = "text" name = "N_hamigua" value = "cantaloupe"/>,document.getelementbyname ("N_hamigua");
However, this method can only get a node with the name attribute, such as <li name = "Li_hamigua" ></li>,document.getelementbyname (Li_hamigua); You should pay attention to this problem when using.
Both the attribute node and the text node need to be fetched to the element node before acquiring it.
Attribute node: <input type = "text" id = "Input_hamihua" value = "Value_hamigua"/>;d Ocument.getelementbyid ("Input_hamigua") . GetAttributeNode ("value");
This allows you to get to the Value property of the input tag, which is the property of "Value_hamigua".
Text node: <li id = "Li_hamigua" > Cantaloupe </li>;d ocument.getelementbyid ("Li_hamigua"). FirstChild;
This allows you to get the text node of the input tag, which is the text value of "cantaloupe".
Explain the difference between the three nodes here:
① ELEMENT nodes: Similar to nodes such as <body></body>, <li></li>, <input/>.
② attribute node: Similar to <input type= "text" name= "text"/> "name= ' text" in such a node.
③ text node: a node similar to "HelloWorld" in <li>HelloWorld</li>.
JavaScript first Knowledge (a): Acquiring nodes