You are targeting $('.div') and not $('.div1') or $('div'). There is no element with class .div in your code, so this is probably a typo.
You also have to change .find() to .next() if you want to trigger the event when hovering over a '.div1' element, since you want to target the next sibling, and not a child.
Here's a working sample you can go by:
https://jsbin.com/vipifolahe/edit?html,js,output
HTML
<div>
<div>
<div class="div1">
</div>
<div class="div2">
</div>
</div>
<div>
<div class="div1">
</div>
<div class="div2">
</div>
</div>
<div>
<div class="div1">
</div>
<div class="div2">
</div>
</div>
</div>
CSS
.div1 {
height: 50px;
background-color: red;
}
.div2 {
height: 50px;
background-color: green;
}
.div2 {
opacity: 0;
}
JS
$(".div1").hover(function () {
$(this).next(".div2").animate({
opacity: "1"
}, {
queue: false
});
}, function () {
$(this).next(".div2").animate({
opacity: "0"
}, {
queue: false
});
});
If you want to trigger the event when the parent div is hovered over, it could look like so:
HTML
<div>
<div class="parent">
<div class="div1">
</div>
<div class="div2">
</div>
</div>
<div class="parent">
<div class="div1">
</div>
<div class="div2">
</div>
</div>
<div class="parent">
<div class="div1">
</div>
<div class="div2">
</div>
</div>
</div>
JS
$(".parent").hover(function () {
$(this).find(".div2").animate({
opacity: "1"
}, {
queue: false
});
}, function () {
$(this).find(".div2").animate({
opacity: "0"
}, {
queue: false
});
});
.divdoesn't exist. Try$("div")instead. Also, if you only want to show the.div2directly after a.div1then you could use CSS for this. Info: developer.mozilla.org/en-US/docs/Web/CSS/…