views:

32

answers:

1

I have an update button on which I want to pull attention when updating my content. I am doing this with an animation color fade and adding some arrow characters.

When the animation is finished I want my CSS :hover states back.
Is this possible or do I lose the original CSS and do I have to reset these with jQuery's hover()

Fiddle: http://jsfiddle.net/K6fd2/

CSS

a.btn { padding: 5px 20px; color: white; background-color: #4188FB; } 
a.btn:hover { background: #FFCC00;}

HTML

<a href="#" class="btn">Update</a>
<br /><br />
<a href="#" class="change">change content</a>

JS

var oriBtnTxt = $(".btn").html(); // store original text

$(".change").click(function() {
    $(".btn")
    .css("background-color","#FFCC00")
    .html(oriBtnTxt + " &raquo;")
    .animate({backgroundColor: "#4188FB"}, 2000, "swing", function() {
        // set back hover state
        $("a.btn:hover").css("background-color", "#FFCC00");
    });
})
+1  A: 

This may not be the most elegant solution, but you could try the following:

$(this).removeAttr('style');

within your $.animate() callback function.

Edit: I suspect that you're losing your :hover styles because $.animate() uses inline styles, which are set after stylesheet rules are evaluated; thus they take precedence over defined styles within the stylesheet.

mway
that works fine for me.. shanks!
FFish
No prob, glad to help.
mway