Reputation: 81
How can I do so that the menu does not ride up when I click inside subbmenyn? (Subbmenu will go up when you click on the main link or outside.) Can it be done without javascript? Then the menu goes over and works with muse over if you do not have javascript enabled.
CODE:
$('.nav > ul').toggleClass('no-js js');
$('.nav .js ul').hide();
$(document).on("click", function(e) {
var $elem = $(e.target);
if ($elem.hasClass('clicker')) {
$('.nav .js ul').not($elem.next('ul')).hide();
$elem.next("ul").slideToggle();
} else {
$('.nav .js ul').hide();
}
})
Upvotes: 1
Views: 130
Reputation:
Simply change the else to check that the clicked element isn't in that container, and that it's not the container. Though you have several elements with the same Id, you should change them to a class
<div class="contentHolder">
so your jQuery would then be
else if (!$($elem).parents('.contentHolder').length && !$elem.hasClass('contentHolder')) {
And you'll need to update the CSS #contentHolder
to .contentHolder
Upvotes: 1