I want a div with text that is only shown when the mouse pointer is set on a specific button.
This is my code:
// Help-text
$("#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 display part works fine. But when I leave the button/container the text should just disappear. Instead it triggers a Christmas Eve-effect.
What is wrong with the basic logic in my code?
Edit: There are a lot of answers on Stackoverflow to achieve this. But I'm actually curious why my specific logic ain't working.