I have this element:
<div style="width: 100%; height: 10px;"></div>
I want to get it's width in pixels. I just tried this:
document.getElementById('banner-contenedor').style.width
Which returns 100%
. Is it possible to actually get the element's width in pixels with JavaScript?
document.getElementById('banner-contenedor').clientWidth
You want to get the computed width. Try: .offsetWidth
(I.e: this.offsetWidth='50px'
or var w=this.offsetWidth
)
You might also like this answer on SO.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With