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)
        }
);

Tags:

2 Responses to “javascript setInterval & clearInterval”

  1. icebreaker says:

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

  2. limborey says:

    more posts going to come soon. :D

    By the way, that’s Javascript, not Java :P

Leave a Reply