Reduce div width repeatedly

I need a specific width <div>to get 50 pixels less each time the JavaScript function is called.

I tried

document.getElementById("Zivot").style.width = "100px";

But this just sets the width and does not add or subtract it.

+4
source share
3 answers

Use this code. Get the width with offsetWidth and reduce it by 50 pixels each time.

var element = document.getElementById('Zivot'); 
element.style.width = (element.offsetWidth - 50) + 'px'; 
+5
source

Pure Javascript way to get this working -

var zivotID = document.getElementById("Zivot");
zivotID.style.width = zivotID.offsetWidth - 50;

document.getElementById( "Zivot" ). style.width myID.style.width. . , , , .

document.getElementById( "Zivot" ). offsetWidth myID.offsetWidth. div/.

-

div, Javascript?

HTMLElement.offsetWidth

HTML?

, :)

+2
var currentWidth = $('#Zivot').width();
$('#Zivot').css('width', currentWidth - 50 + 'px');
0

Source: https://habr.com/ru/post/1622520/


All Articles