Reputation: 975
I have a div with a css style of say green or blue, depending on the nth child color. I set it to orange using
<div id='yo' class='alternatingcolors' style='background-color: #FF9900;'>hello</div>
and I want to animate it back to its original color using jquery's
$('yo').animate({ backgroundColor: 'transparent'}, 500);
However, neither transparent, inherit, null, or '' work.
How would I get it back to its original color? Essentially I want to animate it to the state before: style='background-color: #FF9900;' was set.
Upvotes: 1
Views: 585
Reputation: 144689
you can save its first background-color into a variable and then use it:
orange = $("yo").css("background-color")
Upvotes: 0
Reputation: 32773
The lookup to 'yo' should be prefixed with a hash, e.g.:
$('#yo')
If that's not the issue:
You could store the original colour as data in the div, then restore it later:
<div id='yo' data-original-color='#FF9900' class='alternatingcolors'>
then:
$('#yo').animate({ backgroundColor: $('#yo').data('original-color') }, 500);
Upvotes: 1