I have this code and it doesn’t work; I have no idea why. I tried it in all browsers (IE, chrome, firefox). I suppose that the system must add the class and I tried the console of chrome to see the DOM. I saw the added class but no change in chrome or other browsers.
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<style>
#boton
{
width:200px;
height:30px;
border:1px solid;
background-color:#cccccc;
}
</style>
<style>
.botoncla
{
background-color:#FF0000;
}
</style>
<script>
$(document).ready(function(){
$("#boton").hover(function(){
$(this).addClass("botoncla");
}, function(){
$(this).removeClass("botoncla");
});
});
</script>
</head>
<body>
<div id="boton">Hello</div>
</body>
</html>
Can someone test this? It doesn’t work for me.
Your jQuery code is working but your CSS does not work because the
background-colorof.botoncladoes not overitebackground-colorof#boton.Try with this :
EDIT
However in your case,
!importantis a hack … Maybe you should use.animate()instead :