近期原生js用法
- js获取元素
document.getElementById('sidebar') //获取id元素
document.getElementsByClassName('sidebar') //获取类名元素
document.querySelector("#contatiner") //获取id元素
document.querySelector(".contatiner") //获取class元素
document.querySelectorAll(".con") //获取元素集合
- 获取元素的宽高等
- 如果在css中未设置的属性,使用a.style.* 的方式是无法获取的
- clientHeight (内容高度+padding * 2)
- offsetHeight (内容高度 + 内边距*2 +边框*2)
var a = document.getElementById('a');
a.clientHeight
a.clientWidth
a.offsetHeight
a.offsetWidth