tags:

views:

27

answers:

2

When I hover over the box it doesn't change it's caller as I intent. What's wrong?

<html>
<head><title>test</title></head>
<style type="text/css" >
.box_type1{
    width:560px;
    height:560px;

    background-color:#b0c4de;
}

</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"&gt;&lt;/script&gt;

<script type="text/javascript">

$(document).ready(function(){
$('.box_type1').hover(
    function () {
        $(this).stop().animate({backgroundColor:'#4E1402'}, 300);
        }, function () {
        $(this).stop().animate({backgroundColor:'#943D20'}, 100);
    });

    });
</script>
<body>

</div>

    <div class="box_type1">
    </div>
</body>
</html>
+2  A: 

Your code works, you can see here for a demo.

You'll need either the jQuery color plugin for jQuery UI for this though (to animate most non-numeric properties), for example using UI from the CDN (if you have other uses for UI...use the color plugin if this animation is all you're after, much smaller):

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"&gt;&lt;/script&gt;
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js"&gt;&lt;/script&gt;

Also there's an extra </div> in your <body>, make sure to remove it, invalid HTML causes all sorts of unpredictable behavior, especially cross-browser :)

Nick Craver
You added jQuery UI in that demo, which isn't included in the original code.
Coronatus
@Coronatus - Woops use that setup as a template, I'll update the answer
Nick Craver
+1  A: 
Coronatus