0

I need change the color of a div when the user go over it.

This script I'm trying does not work. Any idea how to fix it?

    <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.js" type="text/javascript"></script>
    <script type="text/javascript">
    $("#arrow-l").hover(
    function() {
        $(this).stop().animate({"background-color": "#999999"}, "slow");
    },
    function() {
        $(this).stop().animate({"background-color": "#BFBFBF"}, "slow");
    });
    </script>
    </head>
...
    <body>
     <div id="arrow-l">prev.</div>
GibboK
  • 71,848
  • 143
  • 435
  • 658

4 Answers4

1

Background color animation won't work using jQuery animate. You have to use jQuery UI for that or use jquery color animation plugin.

jQuery animate backgroundColor

http://www.bitstorm.org/jquery/color-animation/
http://docs.jquery.com/UI/Effects/ColorAnimations

Community
  • 1
  • 1
Praveen Vijayan
  • 6,521
  • 2
  • 29
  • 28
1

From jQuery API doc:

All animated properties should be animated to a single numeric value, except as noted below; most properties that are non-numeric cannot be animated using basic jQuery functionality (For example, width, height, or left can be animated but background-color cannot be, unless the jQuery.Color() plugin is used).

Maybe this helps. Using opacy e. g. worked fine for me.

m02ph3u5
  • 3,022
  • 7
  • 38
  • 51
0

Do you only want to change the background color?

    <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.js" type="text/javascript"></script>
    <script type="text/javascript">
 $(function() {
   $('#arrowl').hover( function(){
      $(this).css('background-color', '#F00');
   },
   function(){
      $(this).css('background-color', '#E0EAF1');
   });
});

    </script>
    </head>
...
    <body>
     <div id="arrowl">prev.</div>
June
  • 793
  • 2
  • 17
  • 43
-1

Refer to LIVE DEMO AT JSFIDDLE

$("#arrow-l").hover(
    function() {
        $(this).css({'background-color': '#999999'});
    },
    function() {
        $(this).css({'background-color': '#BFBFBF'});
    }
);


 <div id="arrow-l">prev.</div>​
Siva Charan
  • 17,940
  • 9
  • 60
  • 95