1

When I hover the button, the background color is not changing.

My jQuery:

<script type="text/javascript" src="/js/jquery.js"></script>  
<script language="javascript" type="text/javascript">  
$(document).ready(function(){  
    $(".reject").hover(function() {  
        $(this).animate({background: '#000'}, 1000);
    }, function(){  
        $(this).animate({background: '#333'}, 1000);  
    });  
});  
</script>  
<style type="text/css">  
    .reject{padding:10px;font-size:20px;background:#F00;} 
</style>  

My html:

<button  class="reject">Reject</button>

What am I missing?

Jason
  • 15,017
  • 23
  • 85
  • 116
Suresh Pattu
  • 6,083
  • 16
  • 59
  • 91

2 Answers2

1

Here is a JSfiddle with it working: JSFiddle

You have to include jQuery UI and then use the following jQuery code.

$(document).ready(function(){  
    $(".reject").hover(function() {  
        // Stop the previous animation (if any) and then animate
        $(this).stop().animate({backgroundColor: '#000'}, 1000);
    }, function(){  
        // Stop the previous animation (if any) and then animate
        $(this).stop().animate({backgroundColor: '#FFF'}, 1000);  
    });  
}); 

Your code was fine, You just have to include jQuery UI. But best to also use the stop function.

Anil
  • 21,730
  • 9
  • 73
  • 100
1

Answer is this
Check this online demo

<script type="text/javascript" src="/js/jquery.js"></script>
//Add this script
<script src="http://www.bitstorm.org/jquery/color-animation/jquery.animate-colors.js"></script>  
<script language="javascript" type="text/javascript">  
$(document).ready(function(){  
    $(".reject").hover(function() {  
        $(this).animate({backgroundColor: '#000'}, 1000);
    }, function(){  
        $(this).animate({backgroundColor: '#333'}, 1000);  
    });  
});  
</script>  
<style type="text/css">  
    .reject{padding:10px;font-size:20px;background:#F00;} 
</style> 

HTML code

<button  class="reject">Reject</button>
Wazy
  • 8,822
  • 10
  • 53
  • 98