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

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -