How to get the id attribute value of the element node

Method 1: Use document.getElementById ();

Method 2: Use document.querySelector ();

document.getElementById("app");
document.querySelector("#app");

 

note: 

1. Method 1 to Method 2 in a lot of high efficiency, a method is recommended;

2. The two methods are the direct target return element nodes, the node instead of a collection of objects;

3. the getElementById () method can only be applied to the document object;

 

Guess you like

Origin www.cnblogs.com/aisowe/p/11543880.html