Chapter III
getElementByIdReturns an object that corresponds to the element node that has the given ID attribute value. document.getElementById (ID) below an example:
1 document.getElementById ("purchases")
getElementsByTagNamemethod returns an array of objects, each corresponding to an element in the document that has a given label. Element.getelementsbytagname (TAG) below an example:
1 document.getelementsbytagname ("li")2 alert (document.getelementsbytagname ("Li"). length);
GetelementsbyclassnameThe HTML5 DOM is new, allowing us to access the element through the class name in the Class attribute. Getelementsbyclassname (Class) below an example:
1 document.getelementsbyclassname ("Sale")
getattributeis a function. It has only one parameter--the name of the property you intend to query Object.getattribute (attribute) below an example:
1 var paras = document.getelementsbytagname ("P"); 2 for (var i=0;i < paras.length;i++) {3 alert (Paras[i].getattribute ("title")); 4 }
SetAttributeIt allows us to make changes to the value of the attribute node. Can only be used for element nodes Object.setattribute (attribute,value) below an example:
1 var shopping = document.getElementById ("purchases"); 2 shopping.setattribute ("title", "a list of goods");
Fourth Chapter
ChildNodesThe Element.childnodes property can be used to get all the elements of any one element, which is an array containing all the child elements of this element, in the following example:
1 var body_element = Document.getelementbytagname ("body") [0]; 2 Body_element.childnodes 3 document.getelementbytagname ("body") [0].childnodes
NodeTypeproperty, each node has a NodeType property. This property allows us to know which node we are dealing with, with a total of 12 desirable values for the Node.nodetypenodetype attribute, but only 3 of them are of practical value. The NodeType attribute value of the element node is 1. The NodeType property value of the attribute node is 2. The NodeType property value of the text node is 3. Here's an example:
1 alert (body_element.nodetype);
NodeValueproperty, which is used to get (and set) the value of a node. Node.nodevalue The following example:
1 alert (decription.nodevalue); 2 alert (decription.childnodes[0].nodevalue);
FirstChildProperties, and
LastChildThe FirstChild property represents the first element of the ChildNodes array LastChild property represents the last element of the childnodes array
Javascriptdom Programming Art _ Learning Notes _ Knowledge point DOM