I'm trying to find out how to edit this jQuery code so that only the parent that is hovered shows its child. At the moment, all the children are shown when any parent is hovered.
Any help much appreciated.
jQuery(document).ready(function($) {
$(".parent").hover(
function () {
$(".child").addClass("hover");
},
function () {
$(".child").removeClass("hover");
}
);
});
.parent {
position:relative;
width:100px;
height:100px;
background:red;
display:inline-block;
float:left;
margin-right:6px;
}
.child {
width:inherit;
height:30px;
position:absolute;
bottom:0;
background-color:blue;
opacity:0;
transition:0.5s;
}
.child.hover {
opacity:1;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="parent">
<div class="child">
</div>
</div>
<div class="parent">
<div class="child">
</div>
</div>
<div class="parent">
<div class="child">
</div>
</div>