2

I have th following script

 $("button#submit").click(function () {
 $("tr[data-id='" + lastRefId + "']").css("background-color", "#8aabf0");
 $("tr[data-id='" + lastRefId + "']").animate({ backgroundColor: "white"}, 'slow');
});

It's a simple script that should change the backgrund to the color above and than change it back to the previous color (white). The first line works, but the second doesn't.

Why and how should I fix it?

4
  • 1
    From the doc: For example, width, height, or left can be animated but background-color cannot be, unless the jQuery.Color() plugin is used) Commented Dec 3, 2013 at 20:48
  • or if you are already using jquery UI, no need to add jQuery.color() plugin Commented Dec 3, 2013 at 20:50
  • possible duplicate of Jquery background animate Commented Dec 3, 2013 at 20:52
  • you need query ui for color animation support, but you should Do this with CSS Commented Dec 3, 2013 at 20:58

1 Answer 1

2

jQuery don't support background color in animation method... by itself
You have to download the jquery-Color.js from the jQuery site and append it after the jQuery source code, then you can use the animation() with background color
The first line works, because you used CSS method and background-color as a CSS property haven't any problem, In second line you used animation...
and you have to write the css properties as an animation argument in camel-case;
for example background-color, must to be backgroundColor

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.