+ 1

why var is not updating in js with setinterval .please check code below.

i have a div div which move left onclick by function move.i have set interval on function and define left in fxn but it is not updating .please help. the cide is like this. function move() { var mydiv = document.querySelector("#divid") ; posnleft = window.getComputedStyle(mydiv).getPropertyValue("left") ; console.log(posnleft); } move(); setInterval(move,1000); now if move div to right it should update value in console after 1s . but it is only repeat of 10px (as in style ) in console.

29th Jun 2020, 10:48 AM
Divya Mohan
Divya Mohan - avatar
3 Réponses
+ 2
I didn't any code that move it right?
29th Jun 2020, 1:41 PM
Calviղ
Calviղ - avatar
+ 1
Because you didn't update value of left selector.
29th Jun 2020, 11:04 AM
Calviղ
Calviղ - avatar
+ 1
can you please explain it a little bit more. i have move it right using js with a btn .
29th Jun 2020, 1:26 PM
Divya Mohan
Divya Mohan - avatar