I`m trying to keep toggle button and $('#popup').blur together but unfortunately the trigger stops hiding. How can I solve this problem?
I have this trigger in header
$(document).ready(function() {
$('#toggle').click(function() {
// this alert always returns 'none'
alert($('#popup').css('display'));
if ($('#popup').css('display') == 'none') {
$('#popup').show().focus();
} else {
$('#popup').hide();
}
});
$('#popup').blur(function() {
$(this).hide();
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<div class="trigger" id="toggle">
<i class="las la-bell"></i>
</div>
When I`m checking Display this alert returns none in spite of Block.
alert($('#popup').css('display'));
Why does it happens? First of all, the code bellow should hide my popup anyway (no matter which element I click), And the thing is that the popup not hidden when it return display:none
$('#popup').blur(function() {
$(this).hide();
});
There is my code: https://codepen.io/webtm/pen/xxrOwMb
I've tried some resources but there is not solution. Toggle a popup and toggle it when clicked outside
Same happens when I use this example
$(document).mouseup(function(e)
{
var container = $("YOUR CONTAINER SELECTOR");
// if the target of the click isn't the container nor a descendant of the container
if (!container.is(e.target) && container.has(e.target).length === 0)
{
container.hide();
}
});
Use jQuery to hide a DIV when the user clicks outside of it
Have you any idea?