Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Repeatedly reduce the width of a div

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.

like image 400
Ivan Avatar asked Mar 13 '23 17:03

Ivan


1 Answers

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'; 
like image 72
Sumit Avatar answered Mar 27 '23 22:03

Sumit