I have been reading some questions at stackoverflow, about how to closing a menu when clicking outside by using jQuery without plugins.
I tried to use event.stopPropagation()
but is not working. Could you tell me how to use it in the next code, and explain why is working in yours?
This is the original code in my webpage, and I want it to do the same function, plus closing it when clicking outside (full code here):
$('.open-popup-on-click').unbind('click').click(function() {
$('#' + $(this).data('popup-id')).toggleClass('hidden');
return false;
});
HTML code (the first div is just a link where users click, and when they do, second div is open as a popup):
<div class="topbar-block topbar-profile-options">
<a class="open-popup-on-click"
data-popup-id="topbar-user-actions"
href="/cuenta"><%=avatar_img(@user, :very_small)%></a>
</div>
<div id="topbar-user-actions" class="hidden popup">
<div style="float: left"><a href="/miembros/<%=@user.login%>"><%=avatar_img(@user, :normal)%></a></div>
<ul style="display: inline-block">
<li><a href="/cuenta">mi cuenta</a></li>
<li><a href="/cuenta/clanes">mis clanes</a></li>
<li><a href="/cuenta/competiciones">mis competiciones</a></li>
<li style="padding-top: 20px; padding-bottom: 20px;"><a href="/miembros/<%=@user.login%>">mi perfil público</a></li>
<li><a class="confirm-click nav" href="/cuenta/logout">cerrar sesión</a></li>
</ul>
</div>
open-popup-on-click
is a class used with all links, from where I want to open a popup. In this case, the popup is the second div, with ID topbar-user-actions
If you still don't understand me, please look this image:
http://i281.photobucket.com/albums/kk205/LEANDRO351/Gamersmafia/exampleMenu.png
Thanks in advance.