It is wrong to use ele.style.width to get the width of an element !!!!!!
In native JavaScript, you can get a CSS element in two ways:
Standard method
window.getComputedStyle(ele)
For example,
var ele = document.getElementById("content"), // Do not use
IE (IE 8 and earlier)
element.currentStyle
For example,
var ele = document.getElementById("content"), // Do not use
Why not use ele.style ?
ele.style is simply an attribute attribute of ele . If you use ele.style.width , you just get the width of ele.style , not the actual width of ele .
If you did something like:
ele.style.width = "55px"
When using ele.style.width you get "55px". If you do not, you will get undefined.
How to do in jQuery?
Use $ele.width() (if you want an βexactβ width, use $ele.outWidth() ), jQuery did everything for you.
Daidai
source share