I need a hidden text inside a div that will only appear when the mouse pointer is hovering over a specific button.
Here is my current code:
// Show help-text on hover
$("#help-container")
.mouseover(function(e) {
$(this).find("#help-text").fadeIn(100).width("80%");
})
.mouseleave(function(e) {
$(this).find("#help-text").fadeOut(100).width("0%");
});
#help-container {
background-color: red;
position: absolute;
top: 0px;
left: 0px;
}
#help-container #help-btn {
padding: 10px;
box-sizing: border-box;
display: inline-block;
background-color: green;
float: left;
}
#help-container #help-text {
width: 0;
display: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="help-container">
<div id="help-btn">Help</div>
<div id="help-text>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</div>
</div>
The functionality seems to be working correctly for showing and hiding the text. However, upon leaving the button/container, the text doesn't disappear as expected.
What could be the issue with the logic of my code?
Edit: While there are alternative solutions available on Stackoverflow, I am specifically interested in understanding why my implementation is not functioning as intended.