Http://www.w3school.com.cn/jsref/index.asp a method for accessing elements in HTML
1.document.getelementbyid ("Id1"), in HTML, the name is an object of the ID1 element. Because the ID of the element is required to be unique, the Getelementid () method is used to obtain an object, not an array.
2.document.getelementbytagname ("H1"), returns a collection of all objects labeled
var li1 = eventlist.getelementbytagname ("li") [0] Gets the first <li> tag contained in the EventList tag.
3. Important attributes of the document: Each node in the document has some important properties, and most importantly
(1). NodeType (which describes what the node is), such as whether the node is a node of an element type (P,h1,li), etc., or a node of a text type, such as
(2). NodeName, which represents the name of the element, such as defining a <textarea id= "MyText" > element in <body>, if using var mynodename = document.getElementById ("MyText"). NodeName; The return value is "TextArea".
(3) NodeValue is the value of a node, and if the node is an element, its nodevalue is null, and if NodeValue is a text node, his value is the contents of the text.
4. Access between parent nodes, child nodes, and sibling nodes:
(1) Access child nodes from parent node: (a). Yourelement.childnodes (), which is the access to all child nodes under the parent node, and the return value is an array of nodes (NodeList). Need to take to a certain time, you can use [1] similar to the index, you can also use the array of attributes to the number of child nodes and so on.
(b). Firstchild,lastchild as the name implies, not much to explain, but one point, a node's properties, such as nodetype,nodename,nodevalue, etc. are considered to be its child nodes, so to access these properties, getElementById ("AAA"). NodeType is inaccessible and requires getelementbyid["AAA"].firstchild.nodetype to be accessed.
(2) Accessing the parent node from a child node: parentnode, which can be accessed by iterating through the parent node
Example: while (Parentelm.classname!) = ' Dynamic ' && parentelm! = ' document.body ')
{
Parentelm=parentelm.parentnode;
}
(3) Access between sibling nodes: You can access the previous sibling node and the next sibling node of the current node using the Element.previoussibling and Element.nextsibling properties.
Important methods in JavaScript for each object