I\'m curious why this one
.overlay{
width: 100px;
height: 200px;
background-color:red;
}
The style gives access only to information which is put into elem.style
. In your example style doesn’t tell anything about the margin defined in CSS. Use getComputedStyle().
var computedStyle = getComputedStyle(document.getElementsByClassName("overlay")[0], null)
alert(computedStyle.width);
jsfiddle demo