Tuesday, April 12, 2011

jQuery selectmenu - call back

The jQuery selectmenu  documentation is kind of confusing, it lacks of examples and documentations.  Well, it covers how to use this plugin in its basic way, but nothing more.

I came across this problem of firing callback when the menu is changed. The documentations says;
Callback events The selectmenu plugin provides callbacks for open, close, select, and change events, allowing you to execute scripting based on those events. The change event even triggers a change event on the original select element, allowing you to reliably track form change events.

Do you pass your call back in as one of your config parameter or what?? And finally it is how it works:

// You first need to initialize the select menu and bind your element
$('.menu-drop').selectmenu({ style: 'dropdown' });

// Now there are some new functions bind to ".menu-drop" that you can use

$('.menu-drop').change(function () {
        //either ajax call or whatever you want
});


Well, of course, you should be able to chain that (recommended) ~

$('.menu-drop').selectmenu({ style: 'dropdown' }).change(function () {
        //either ajax call or whatever you want
});


No comments:

Post a Comment