Is there a way to use jQuery mouseover to maintain its functionality even if the element is positioned outside of the parent element?
For example, in the code snippet provided, the yellow list should remain active on mouseover, even if I navigate to it. Currently, the mouseout event is triggered when moving to the yellow list.
The yellow list should be hidden when leaving both the yellow list and the current link of the blue list.
$("ul > li")
.mouseover(function() {
$(this).addClass('active').has('ul').addClass('has-children');
if($(this).hasClass('has-children')){
$(this).find('ul').first().addClass('visible');
}
})
.mouseout(function() {
$(this).removeClass('active');
$(this).has('ul').removeClass('has-children visible');
$(this).find('ul').removeClass('visible');
});
body {
background:red;
}
div {
position:relative;
}
ul {
background:blue;
color:white;
padding:10px;
}
div > ul {
position:absolute;
left:0;
}
div ul > li > ul {
position:absolute;
left:200px;
top:0;
display:none;
}
.visible {
display:block;
}
li.active ul {
background:yellow;
color:black;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<ul>
<li>Link 1
<ul>
<li>Link 2</li>
</ul>
</li>
<li>Foo</li>
<li>Bar</li>
</ul>
</div>