0
$("div.test").mouseenter(function() {
                                    $("div.innerDiv").fadeIn("slow");
            }).mouseleave(function() {               
                                    $("div.innerDiv").fadeOut("slow");
            });   

<div class="test">
<div class="innerDiv">1</div>
</div>

<div class="test">
<div class="innerDiv">2</div>
</div>

<div class="test">
<div class="innerDiv">3</div>
</div>

<div class="test">
<div class="innerDiv">4</div>
</div>

So how this currently behaves right now is that if I mouseover any of the divs then all of them would fade in. I want only the div that I hover over to fade in and not all of them. I think there is a way to change the jQuery without changing the structure of my div, but I don't know how.

Strawberry
  • 66,024
  • 56
  • 149
  • 197

3 Answers3

2
$("div.test")
    .mouseenter(function() {
        $(this).find("div.innerDiv").fadeIn("slow");
    }).mouseleave(function() {               
        $(this).find("div.innerDiv").fadeOut("slow");
    });   
simshaun
  • 21,263
  • 1
  • 57
  • 73
1

Here you go.

$("div.test").mouseenter(function() {
                $('div.innerDiv',this).fadeIn("slow");
            }).mouseleave(function() {               
                $('div.innerDiv',this).fadeOut("slow");
            }); 
Lime
  • 13,400
  • 11
  • 56
  • 88
1

Use this instead of a string as your selector

Check this

$(".test").mouseenter(function() {
    $(this).fadeOut("slow");
}).mouseleave(function() {               
    $(this).fadeIn("slow");
});   

By the way, I think you want to fadeOut first, not fadeIn

vinceh
  • 3,490
  • 1
  • 21
  • 24