I have a menu where user clicks on link and list appears via .addClass( "show-nav" )
.
Here is jsFiddle with JS code:
jQuery(".nav-js-trigger").each(function(){
this.onclick = function() {
var hasClass;
hasClass = jQuery(this).next().hasClass( "show-nav" );
jQuery('.show-nav').removeClass('show-nav');
if (hasClass === false) {
jQuery(this).next().addClass( "show-nav" );
}
}
});
I want to remove the class show-nav
if the user clicks outside of the div with class show-nav
. How do I do this?
I have seen examples of e.target
div ID but not class, particularly not a scenario like this.