tags:

views:

61

answers:

1

My DOM looks like:

<body>  <div class="c1"> 
              <div class="c2">
              ...
              </div>
              <div class="c3">
                      <div class="thisone">....</div>
              </div>
        </div>
        <div class="c1"> 
              <div class="c2">
              ...
              </div>
              <div class="c3">
                      <div class="thisone">....</div>
              </div>
        </div>
        <div class="c1"> 
              <div class="c2">
              ...
              </div>
              <div class="c3">
                      <div class="thisone">....</div>
              </div>
        </div>
         </body>

The div element with class 'thisone' is hidden currently.

During a mouseover of the class c1, I want the div with 'thisone' to be visible, and hidden during a mouseout.

How can I do this using jQuery? I want to drill down as much as possible to make it efficient but I'm not sure exactly how to do that.

+4  A: 

Surest and easiest way:

$(window).ready(function(){
  $(".c1").hover(
     function(){
       // mouse in
       $(this).children(".thisone").stop().fadeIn(); // you can change fadeIn to show
     },
     function(){
       // mouse out
       $(this).children(".thisone").stop().fadeOut(); // you can change fadeOut to hide
     }
  );
});
thephpdeveloper
what is the stop() for?
jrhicks
if you try it out really quickly, you will know that stop() helps with responsiveness - this is because animation in jQuery are queued. You need to stop the current animation to continue the next to increase responsiveness.
thephpdeveloper
To stop any animation currently occurring. You can have visual artifacts or incorrect functionality without using it.
cletus