Change background color on mouseover and remove it after mouseout

Total Post:1

Points:7
JQuery 
 313  View(s)
Ratings:
Rate this:

I want to change the background color on mouse hover .This code works fine but I think this is not the right code

<script type="text/javascript">

    $(document).ready(function() {
        $('.test').bind("mouseover", function(){
            var color = $(this).css("background-color");

            $(this).css("background", "#380606");

            $(this).bind("mouseout", function(){
                $(this).css("background", color);
            })
        })
    })
</script>

can anyone tell me some other solution?

  1. Post:2

    Points:14
    Re: Change background color on mouseover and remove it after mouseout

    try this code

    <script>
    
    $(document).ready(function(){
        $(".test").hover(function(){
            $(this).css("background-color", "yellow");
            }, function(){
            $(this).css("background-color", "pink");
        });
    }); </script>


Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!