Javascript element style
css, javascript
Solution
The JavaScript `.style` only relates to inline styles on the element.
See Documentation.
If you want to get the width of an element you should use `offsetWidth`.
document.getElementsByClassName("overlay")[0].offsetWidth
http://jsfiddle.net/9kwap3zy/7/
Problem
I'm curious why this one ``` <div class = "overlay"> fdsfsd </div> .overlay{ width: 100px; height: 200px; background-color:red; } alert(document.getElementsByClassName("overlay")[0].style.width); ``` is not alerting nothing. Of course I can write `<div style = "width:100px">` then everthing works fine, but it is not good for me, I need css. Here you can find a jsfiddle demo So exact question is: why this code is not alerting width of div and how alert it if width is given by css?