Reputation:
I have problems in clicking on the links from a dropdown-menu
By clicking on the link logout.php the dropdown-menu closes and does not open the link
I can not log out, because the dropdown-menu does not allow me to follow the link, how can I solve this problem?
My code jQuery dropdown-menu:
$(document).ready(function() {
$('.navigation li a').click(function() {
var parent = $(this).parent().attr('id');
if ($('#'+parent+' .Idropdown-menu').is (':hidden')) {
$('.Idropdown-menu').hide();
$('#'+parent+' .Idropdown-menu').show();
} else {
$('.Idropdown-menu').hide();
}
return false;
});
$(document).on('click', function (e) {
if ($(e.target).closest(".Idropdown-menu").length === 0) {
$(".Idropdown-menu").hide();
}
});
});
Code execution https://jsfiddle.net/j30vd27o/1/
Upvotes: 0
Views: 40
Reputation: 1398
The problem is that you are overwriting the a click response and then returning false on every click. This is preventing your code from correctly following the link. You can probably rewrite it to be like this:
$('.navigation li a').click(function() {
var parent = $(this).parent().attr('id');
if ($('#'+parent+' .Idropdown-menu').is (':hidden')) {
$('.Idropdown-menu').hide();
$('#'+parent+' .Idropdown-menu').show();
return false;
} else {
$('.Idropdown-menu').hide();
console.log("hiding")
return true;
}
});
Also will your dropdown be full of href links that go to another page? If so you may be able to get ride of the else statement all together.
Upvotes: 1