I am trying to make a panel that opens when she clicks on a button. I have a button, I have a panel. With the click() event, it opens. When this button is pressed again, it closes.
$('#button').click(function() { $('#panel').toggle(); });
I want to achieve this if the user clicks everywhere except #button or #panel , it also closes.
PS I tried something similar, but this is not the desired behavior.
$('#button').mouseenter(function() { $('#panel').show(); }).mouseleave(function() { setTimeout(function() { $('#panel').hide(); }, 2000); });
source share