I'm trying to create a generic 'flash of color confirmation' function where it'll flash the background of an object to green and then fade out to whatever it's existing color was.
So I may have two elements that I call this on click():
li background-color: red
li background-color: black
If I click the first one, it'd fade from green to red. If I click the first one, it'd fade from green to black.
The jQuery logic:
click event:
listItem.each(function(){confirmFlash($(this),$(this).css("backgroundColor"))});
the function:
function confirmFlash(objectToFlash,backgroundColor){
objectToFlash.css("backgroundColor","#84da9a").animate({opacity: 1}, 1000).animate({backgroundColor: backgroundColor}, 500);
}
This works great. The catch:
If I also give the above LI's a :hover state background color:
li background-color: red
li background-color: black
li:hover background-color: purple
Then all of my fades go from green to purple. That makes sense, since at the time of clicking the LI, the background is, indeed, purple.
Is there a clever way to grab the 'non-hover' CSS class's back-ground color?
A way to reword it is that I'd like to grab the background color assigned to the LI's current class, rather than pseudo class.
Or is the solution to implement the hover not by CSS, but do it via jQuery as well?