Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the selected item

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);
    }
});​
like image 951
Uder Moreira Avatar asked Dec 18 '12 16:12

Uder Moreira


1 Answers

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

like image 93
Pow-Ian Avatar answered Oct 03 '22 08:10

Pow-Ian