Javascript element style

后端 未结 4 1151
名媛妹妹
名媛妹妹 2021-01-12 09:14

I\'m curious why this one

fdsfsd
.overlay{ width: 100px; height: 200px; background-color:red; }
4条回答
  •  庸人自扰
    2021-01-12 09:48

    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/

提交回复
热议问题