javascript - How does setInterval() work with button.onclick -


i want alertme function called when button clicked, gets called (the setinterval gets called calls that) page loads. if take pageload function away, startbutton null , can't it.thanks in advance, guys!

/when user clicks start, start animation window.onload = pageload;  function pageload() {     var startbutton = document.getelementbyid("start");      startbutton.onclick = setinterval(alertme,200); }  function alertme() {   alert("hi"); } 

function pageload() {     var startbutton = document.getelementbyid("start");      startbutton.onclick = alertme; }  function alertme() {   setinterval(function(){     alert("hi");   },200); } 

move interval inside alertme function, , pass reference startbutton.onclick

demo: http://jsfiddle.net/ghs4a/


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -