do something later with settimeout or loop with setinterval


This one will run a certain time after the document loads. So if i want to execute something 5 seconds (or so) after the page loads i would do this.

You will need to check your console log to see the results for this one.

function doSomething() {
  console.log("doing something!");
setTimeout(doSomething, 5000);


setInterval is for if you would like to loop something over and over again usually.

setInterval(function(){ console.log("doing something every 3000ms"); }, 3000);

What cool stuff can we do with this?

Hmm... let me think

What if we add and remove a class from a div and animate it with css?

another example of this can be found here using toggleClass and transitions


Other Items in js
Page Views

This page has been viewed 44 times.

Search Code
Search Code by entering your search text above.

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.