I need the width of a specific <div>
to get smaller by 50px every time a JavaScript function is called.
I tried
document.getElementById("Zivot").style.width = "100px";
But that just sets the width, and doesn't add or subtract it.
Use this code. Get the width using offsetWidth and reduce it by 50px every time.
var element = document.getElementById('Zivot');
element.style.width = (element.offsetWidth - 50) + 'px';
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