DEV Community

how to check if a value has changed in javascript webbrowser

do

var old = /*value*/
function loop(){
 if (/*value*/ != old){ //check if the value is not old
  //do stuff
 }
 old = /*value*/ //set old to value
 requestAnimationFrame(loop) //loop every frame
}
requestAnimationFrame(loop) //wait a frame
Enter fullscreen mode Exit fullscreen mode

or

var old = /*value*/
function changed(){
 var change = /*value*/ != old //check if the value is not old
 old = /*value*/ //set old to value
 return change //output change
}
Enter fullscreen mode Exit fullscreen mode

and replace /*value*/ with the value to check :)

Top comments (0)