Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

setinterval on and off

//setinterval on and off

h1 = document.querySelector("h1")
h2 = 0
document.querySelector("#onoff").value = "On"

function funi(){
  tr = setInterval(() =>h1.innerHTML = h2 ++, 1000)
  }

function onoff(){
  currentvalue = document.getElementById('onoff').value;
  if(currentvalue == "Off"){
  clearInterval(tr)
  document.getElementById("onoff").value="On";
  }else{
    funi()
    document.getElementById("onoff").value="Off";
  }
}
 
PREVIOUS NEXT
Tagged: #setinterval
ADD COMMENT
Topic
Name
6+6 =