I got the following html:
<div id="otherdiv"></div>
<div class="overlay">
<div class="menu">
<ul>
<li><a href="#">Val1</a></li>
<li><a href="#">Val2</a></li>
</ul>
</div>
</div>
and JS code:
$(document).ready(function(){
$('#otherdiv').on('mouseup', function(e){
var left = e.clientX + "px";
var top = e.clientY + "px";
var div = $('.overlay');
div[0].style.left = left;
div[0].style.top = top;
$(".overlay").show(200);
});
$(document).on('click', function(e) {
$('.overlay').hide(200);
});
});
I need to hide my .overlay
when the user clicks somewhere outside it and show it when the user clicks #otherdiv
. When I attach an event to document
and click on otherdiv
, my overlay shows and then immediately hides. How to fix that behaviour? Thank you.