Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery how to make event occur every x seconds?

$("#clickMe").click(                                    
     function(){   
          if (i == 1) {            
               i = i+1
               $("#div p").css("left", "-" + width * i + "px");  
            }
});

As you can see -margin changes when somebody clicks a button. What if I want it to happen just on site load every 10 seconds?

Thanks.

like image 319
fomicz Avatar asked Sep 25 '10 00:09

fomicz


1 Answers

Use setInterval to set up a timed event:

setInterval(
     function(){   
          if (i == 1) {            
               i = i+1
               $("#div p").css("left", "-" + width * i + "px");  
            }
     },
     10000  /* 10000 ms = 10 sec */
);
like image 126
casablanca Avatar answered Sep 27 '22 16:09

casablanca