Add class after 10 seconds
javascript, jquery
Solution
Try using setTimeout specifying 10 seconds delay.
$('.albums img').on('click',function(){
var $this = $(this).addClass('playing');
window.setTimeout(function(){
$this.addClass('finsihed');
}, 10000); //<-- Delay in milliseconds
});
Problem
I have a div where when I click it, it adds a class of 'playing'. Then, after 10 seconds, I want to add a class of 'finished'. I have this code, but how do I time it so after 10 seconds, it adds the class of finsihed? ``` $('.albums img').on('click',function(){ $(this).addClass('playing'); }); ``` Any help is appreciated! Thanks a ton everyone. I used this question to show ~30 students at HackerYou how to use stackoverflow to get top notch help from the community.