Change background color in seconds with jQuery only

When I click on a specific element, I want another background element to become, say, red for x seconds before returning to its original color, all without using jQuery UI, only jQuery. Is it possible?

+7
source share
3 answers
var $el = $("#my-element"), x = 5000, originalColor = $el.css("background"); $el.css("background", "red"); setTimeout(function(){ $el.css("background", originalColor); }, x); 
+14
source
 $("#element1_ID").on('click', function() { // click on first element var bg = $("element2_ID").css('background'); // store original background $("element2_ID").css('background', 'red'); //change second element background setTimeout(function() { $("element2_ID").css('background', bg); // change it back after ... }, 1000); // waiting one second }); 
+3
source

Check FIDDLE

 $('.b').on('click', function() { var time = 2000; setTimeout(function() { $('.a').css("background-color", "green"); }, time); });​ 
0
source

All Articles