Three methods for JavaScript to get nodes from html
How to get a node:
1. getElementById: Get the reference of the first object whose ID tag attribute is the specified value
2. getElementsByName obtains the object set based on the value of the NAME tag attribute.
3. getElementsByTagName obtains the object set based on the specified element name.
<Auxiliary> three attributes of each node: nodeName, nodeType, and nodeValue
NodeType: Label nodeoType is 1, attribute is 2, content is 3
The following shows three methods to obtain html nodes:
Dom_1.html <Script type = text/javascript>
// 1, getElementById function getNode1 () {var a = document. getElementById (divid); // obtain the Node object through the node id // alert (a); alert (. nodeName +, +. nodeType +, +. nodeValue); // The Name Of The div node // The nodeoType of the label is 1, the attribute is 2, and the content is 3 // nodeValue the label type node is null and has no value. Only attributes and text nodes can have values. // Obtain the content in the node only under the obtained node. // obtain the innerHTML innerText attribute var text = a in the div node. innerHTML; // set or obtain the HTML in the object's start and end tags. Alert (text); // change the attribute a. innerHTML = to something else. Note that innerHTML can modify the content. fontcolor (blue );}
// 2. getElementsByName obtains the object set based on the value of the NAME tag attribute. Function getNode2 () {var a = document. getElementsByName (aa); alert (. nodeName); // undefined a is an array. You must specify an element to use alert (a [0]. nodeName +-+ a [0]. nodeType +-+ a [0]. nodevalue );}
3,
Function getNode3 () {var a = document. getElementsByTagName (div); alert (. nodeName); // undefined a is an array. You must specify an element to use alert (a [0]. nodeName +-+ a [0]. nodeType +-+ a [0]. nodevalue) ;}</script>
This is the region where div is used. I am the best !! The effect is as follows: