DOM节点操作
- 获取DOM节点
- prototype,获取JS对象上的属性
- Attribute,获取DOM标签上的属性
获取DOM节点
var div1 = document.getElementById('div1');
var divList = document.getElementByTagName('div');
console.log(divList.length);
console.log(divList[0]);
var containerList = document.getElementByClassName('.container');
var pList = document.querySelectorAll('p');
property
var pList = document.querySelectorAll('p');
var p = pList[0];
console.log(p.style.width);
p.style.width = '100px'
console.log(p.className);
p.className = 'p1'
console.log(p.nodeName);
console.log(p.nodeType);
Attribute
var pList = document.querySelectorAll('p');
var p = pList[0];
p.getAttribute('data-name');
p.getAttribute('data-name','imooc');
p.getAttribute('style');
p.setAttribute('style','font-size:30px;');