怎样通过id属性值获取元素节点

方法1: 使用document.getElementById();

方法2: 使用document.querySelector();

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

注意: 

1. 方法1比方法2的效率高很多, 建议使用方法1;

2. 两个方法都是直接返回目标元素节点, 而非节点集合对象;

3. getElementById()方法只能作用在document对象上;

原文地址:https://www.cnblogs.com/aisowe/p/11543880.html