Reputation: 43
When clicking on a link in a zurb foundation 4 dropdown, the link does not close the drop down. What is the best way to do this systematically across the site?
I have created the following function to solve this problem. Is this the best way to do it, or am I missing something?
$('.f-dropdown').click(function(){
if ($(this).hasClass('open')) {
$('span[data-dropdown="'+$(".f-dropdown").attr('id')+'"]').trigger('click');
}
});
Upvotes: 4
Views: 3363
Reputation: 351
I use this to change the behavior of all dropdown buttons in a page in zurb foundation 3.2.5. Haven't tested it in 4, but as it's a different method here it goes.
$(document).ready(function () {
$('.button.dropdown').find('li').click(function () {
$(this).parents('.button.dropdown')[0].click();
});
});
Upvotes: 0
Reputation: 5715
You also need the data-dropdown-content attribute attached to the dropdown ul element.
Reference: https://github.com/zurb/foundation/issues/1831#issuecomment-15133817
Upvotes: 0
Reputation:
You probably already corrected it in your own code but it will work better this way if you have more than one dropdown on your webpage:
$('.f-dropdown').click(function() {
if ($(this).hasClass('open')) {
$('span[data-dropdown="'+$(this).attr('id')+'"]').trigger('click');
}
});
Upvotes: 5