Menu icon Foundation
Foundation dropdown event trigger

How does ones find out the element that triggered a dropdown. I want to perform a custom action that depends on the element that triggered the dropdown to open:

$("[data-dropdown-content]").on('opened.fndtn.dropdown', function(e) {
    
    if ($(elementThatFiredOffEven).is('.my-button')){
        //do this
    } else {
        //do something else to the dropdown
    }
    
        
});

dropdown

How does ones find out the element that triggered a dropdown. I want to perform a custom action that depends on the element that triggered the dropdown to open:

$("[data-dropdown-content]").on('opened.fndtn.dropdown', function(e) {
    
    if ($(elementThatFiredOffEven).is('.my-button')){
        //do this
    } else {
        //do something else to the dropdown
    }
    
        
});
Ricky over 4 years ago

Cheers, but I'm trying to find the element that fired off the dropdown. Say I had 3 buttons that all fired off the same dropdown (in this case, I've built a mega menu), and I want to add a new class to the $("[data-dropdown-content]") based on the button that triggered it.

Ricky over 4 years ago

I guess what I'm trying to get is the target from:

 open : function (dropdown, target) {} 

Ricky over 4 years ago

Found it.

 $("[data-dropdown-content]").on('opened.fndtn.dropdown', function(e) {
        console.log(Foundation.libs.dropdown.S(this).data('target'));
    });

Rafi Benkual over 4 years ago

Ok, gotcha, thanks for sharing your solution!

Lethunder over 3 years ago

Hello guys, i have the same problem.i'm trying to handle on click event on dropdown menu with submenu but no way.Ricky solution doesn't work for me.any idea please?