Barney
Barney

Reputation: 1848

JQuery Javascript background colour change/highlight

Can you do a simple table row change bg colour for x seconds then change back in pure Javascript or JQuery?

What I've tried doesn't seem to work, and I'd rather avoid the use of any further plugins seeing as I've done everything else in JQuery or Javascript alone.

What I'm after is a flash/ short highlight effect.

Upvotes: 0

Views: 815

Answers (2)

Ayush
Ayush

Reputation: 42440

Headshota's method will work. here is an alternative way.

$('#yourelementid').addClass('backgroundClass').delay(5000).queue(function(){$('#yourelementid').removeClass('backgroundClass');});

And then define a CSS class

.backgroundClass { background:blue;}

Demo

Upvotes: 1

Headshota
Headshota

Reputation: 21449

$('tr.yourRow').css({'background-color': 'red'});

setTimeout(function(){
   $('tr.yourRow').css({'background-color': 'blue'});
}, 6000);

Upvotes: 3

Related Questions