Fade the background-color of a span tag with JQuery

Russ Clark picture Russ Clark · Apr 9, 2009 · Viewed 50.8k times · Source

I'm trying to fade the background-color of a span tag using JQuery to emphasize when a change has occured. I was thinking the code would be someting like the following inside the click handler, but I can't seem to get it working. Can you show me where I went wrong? Thanks Russ.

$("span").fadeOut("slow").css("background-color").val("FFFF99");

That's better, but now it fades both the background-color of the span tag and the text value of the span tag too. I'm trying to just fade the background-color and leave the text visible. Can that be done?

Answer

mishac picture mishac · Apr 9, 2009

It can be done with the color animation plugin. You'd then do something like

$('span').animate({'backgroundColor' : '#ffff99'});