javascript setInterval & clearInterval

An example to demonstrate how start interval & stop it using javascript.

var x = window.setInterval(
	function(greeting, name){
		var m = document.createElement("div");
                with(m.style){
                    height = "2px";
                    width = "50px";
                    position = "relative";
                    backgroundColor= "green";
                }
                document.body.appendChild(m);
	},
	1000,
	"hello",
	"world",
        document.body.onclick = function(){
	    clearInterval(x)
        }
);
Explore posts in the same categories: Javascript

Tags:

You can comment below, or link to this permanent URL from your own site.

2 Comments on “javascript setInterval & clearInterval”

  1. icebreaker Says:

    cool, post some more if possible!!! i forgot java now.


Comment: