Dean Elliott
Dean Elliott

Reputation: 729

jQuery, temporarily add class for xx milliseconds

Is it possible to temporarily add a class to an element and then remove it again after xx milliseconds?

For example;

When I click on an element with the class .trigger can I add a class of .loading to another element with a class of .menu and then, after say 500ms, remove the .loading class again?

Upvotes: 0

Views: 2781

Answers (1)

Mathieu Labrie Parent
Mathieu Labrie Parent

Reputation: 2596

You can do this with a setTimeout like this :

$("MyControl").addClass("loading");
setTimeout(function () {
     $("MyControl").removeClass("loading");
},500);

Upvotes: 4

Related Questions