0

I wrote a simple program to see if jQuery was working locally, turns out it was not. In this program hovering over the red box changes the box with no color below it to green.

Here is the JSFiddle: http://jsfiddle.net/sBk3M/495/

Here is the code locally (it doesn't work).

<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script>

<style type="text/css">
    .hoverbox {
        background-color:red;
        width:20px;
        height:20px;
    }

    .showbox {
        width:20px;
        height:20px;
    }
</style>

<script type="text/javascript">

    $('.hoverbox').hover(function() {
        $('.showbox').css("background-color", "green");
    });

</script>

</head>

<body>
    <div class="hoverbox">
    </div>

    <div class="showbox">
    </div>

</body>


</html>

2 Answers2

1

Put this code

$(function(){
     $('.hoverbox').hover(function() {
            $('.showbox').css("background-color", "green");
        });

    });
vaibhav kulkarni
  • 1,277
  • 11
  • 19
1

You can use like below :

$(document).ready(function(){
      $('.hoverbox').hover(function() {
          $('.showbox').css("background-color", "green");
      });
});

Reference for using $(document).ready() is jQuery Dom Ready

Rajasekhar
  • 509
  • 1
  • 4
  • 14