1
There is a read with the id 'user-login-menu' that when clicked opens a div with a sub-menu, but it is only possible to close it by clicking again on the li. I would like it to be possible to close the div by clicking both on the li and outside it.
I’ve tried with e.stoppropagation() but it didn’t work, maybe I applied it wrong, I’d be grateful if someone could help.
$('#user-login-menu').click(function() {
$('.dropdown-login').fadeToggle(200, function() {
});
});
#user-login-menu {
cursor: pointer;
}
.dropdown-login {
display: none;
position: absolute;
top: 70px;
right: 0;
background: #fff;
width: auto;
height: auto;
border-width: 0 1px 1px 1px;
border-style: solid;
border-color: rgba(0,0,0,0.3);
}
.dropdown-login li {
display: block;
background: #fff;
border: 0;
width: auto;
height: auto;
float: none;
}
.dropdown-login li:hover {
background: red;
}
.dropdown-login li a {
padding: 0 25px 0 25px;
text-align: left;
color: #000;
font-size: 16px;
line-height: 40px;
display: block;
font-family: 'Roboto', sans-serif;
font-weight: 700;
letter-spacing: 0;
}
.dropdown-login li a:hover {
color: #fff;
}
<li id="user-login-menu"><a>Avatar</a></li>
<div class="dropdown-login">
<li><a href="/login/">Login</a></li>
<li><a href="/registrar/">Registrar</a></li>
</div>
You want it to close by clicking anywhere on the screen other than itself
<li>
?– Leonardo Pessoa
Yes, close by clicking on the li or anywhere outside it
– Gabriel Souza