I\'m curious why this one
fdsfsd .overlay{ width: 100px; height: 200px; background-color:red; }
The JavaScript .style only relates to inline styles on the element.
.style
See Documentation.
If you want to get the width of an element you should use offsetWidth.
offsetWidth
document.getElementsByClassName("overlay")[0].offsetWidth
http://jsfiddle.net/9kwap3zy/7/