Calvin Cheng Calvin Cheng - 6 months ago 17
Javascript Question

Closing the dropdown button programmatically

I am using this zurb-foundation dropdown button - http://foundation.zurb.com/sites/docs/v/5.5.3/components/dropdown_buttons.html

But I have an additional requirement to close the dropdown list when a user clicks outside the dropdown button itself or when the user clicks on an item in the dropdown list, so I need a way to programmatically close an open dropdown list on an on-click event.

What's the javascript call I need to make to programmatically close an open dropdown list?

Answer

After some searching here is a slightly cleaner way of doing it:

Foundation.libs.dropdown.close($('#id_of_dropdown_list'));