I have a issue,
Im trying to make a popup toggle with toggleClass
. However i also made a rule that i got from StackOverflow that makes the popup dissapear when clicked outside.
However when i click the button login it appears, but i cant make it dissapear with the login button anymore. But i have set the rule :
$('a#inloggen').click(function() {
$('.inloggen').toggleClass('active');
});
However it seems like he is ignoring that...
Prehaps you guys can spot what the issue is that i can not see.
HTML
<div id="usermenu">
<div class="inloggen"><h2 class=" swe-editable" _sweid="17" _sweclass="nl swe swe-snippet swe-h2 ">
Inloggen</h2>
this is the popup!
<p> </p>
<p> </p>
<p>Wachtwoord vergeten? <a href="#">Klik hier</a>.</p></div>
</div>
<ul class="menu">
<li class="first"><a href="#" id="inloggen">login</a></li>
</ul>
jQuery
$('a#inloggen').click(function() {
$('.inloggen').toggleClass('active');
});
$(document).mouseup(function (e)
{
var container = $('.inloggen');
if (container.has(e.target).length === 0)
{
container.removeClass('active');
}
});
if ($('#project_user_loginform-name').hasClass('error') || $('#project_user_loginform-password').hasClass('error')) {
$('.inloggen').addClass('active');
};
What have i tried?
I tried to add a exception to the function that makes the div dissapear when clicked outside the div but this just seems to reverse the progress.
var container2 = $('a#inloggen');
if (container.has(e.target).length === 0 && container2.has(e.target).length !== 0)
UPDATE :
I got a bit further in the progress and changed mouseup to mousedown and changed the order of the functions. This gives me a bit closer to the solution however its not working perfectly yet.
$(document).mousedown(function (e)
{
var container = $('.inloggen');
if (container.has(e.target).length === 0)
{
container.removeClass('active');
}
});
$('a#inloggen').click(function() {
$('.inloggen').toggleClass('active');
});
Example
http://codepen.io/anon/pen/ghpwr