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
Comments
Post a Comment