Commonly used DOM methods in JavaScript include: 1. getElementById; 2. getElementsByClassName; 3. getElementsByTagName; 4. getAttribute; 5. setAttribute.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
一、
1、getElementById
2、getElementsByClassName
3、getElementsByTagName
4、getAttribute
5. setAttribute
2.
There are the following three methods that can be called to obtain element nodes from the document object
1. getElementById
document.getElementById( id) According to the ID, an object corresponding to the element node with the same id attribute will be returned
2. getElementsByClassName
document.getElementsByClassName(class) According to the class name, an object array will be returned , corresponding to a specific set of element nodes in the document
3, getElementsByTagName
element.getElementsByTagName(Tag) According to the tag name, an object array will be returned, corresponding to a specific set of element nodes in the document Element node
Secondly, there are two methods that cannot be called from the document object, but can only be called through the element node object
1. getAttribute
object.getAttribute(attribute) only Use one parameter to query and obtain the name of the attribute
2, setAttribute
object.setAttribute(attribute, value), you can modify the value of the attribute node
[Recommended learning: javascript advanced tutorial]
The above is the detailed content of What are the common methods of DOM in JavaScript?. For more information, please follow other related articles on the PHP Chinese website!