I am creating a drop-down shopping basket, so I need a way to open the pop-up menu programmatically. Is there any way?
I tried this:
$(document).foundation('dropdown', 'open', ($('#top-bar-cart'), $('.top-bar-cart-link'));
Foundation.libs.dropdown.open($('#top-bar-cart'), $('.top-bar-cart-link'));
And this:
$('.dropdown-btn').trigger('click');
But still failed.
EDIT:
I think I found the problem. I used the code inside the click event to test it so I need it:
e.stopImmediatePropagation();
for it to work. Full example:
$('#button').click(function(e) { e.preventDefault(); e.stopImmediatePropagation(); // use this (most correct way, I think) Foundation.libs.dropdown.open($('#top-bar-cart'), $('.top-bar-cart-link')); // or this //('.top-bar-cart-link').trigger('click'); });
Thanks for the comments!
source share