11

Sorry if my question is too simple, but I can't figure it out from the jQuery UI documentation.

How can I determine which option was clicked within a menu? I tried something like this but it didn't work:

var menu = $('#menu');
menu.menu({
    select: function(event, ui) {
        alert(ui.type);
    }
});​
Yuck
  • 49,664
  • 13
  • 105
  • 135
Uder Moreira
  • 865
  • 6
  • 17
  • 33

1 Answers1

19

What you are missing is the fact that 'ui' is a jQuery object that represents the item you clicked.

so to get the text out of that item you should be using:

    var menu = $('#menu');

    $(document).ready(function(){
        menu.menu({
            select: function(event, ui) {
                alert(ui.item.text());
            }
        });
    });

That will give you the text of the item.

here is a Fiddle

Pow-Ian
  • 3,607
  • 1
  • 22
  • 31