Home  >  Article  >  Web Front-end  >  What are the common methods of DOM in JavaScript?

What are the common methods of DOM in JavaScript?

醉折花枝作酒筹
醉折花枝作酒筹Original
2021-07-15 14:33:454680browse

Commonly used DOM methods in JavaScript include: 1. getElementById; 2. getElementsByClassName; 3. getElementsByTagName; 4. getAttribute; 5. setAttribute.

What are the common methods of DOM in JavaScript?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn