catch data-attribute after jQuery selectmenu

977 views Asked by At

I am unable to catch the data-attribute after the applying jQuery UI select menu on it.

How is it possible to get the data?

HTML:

<select class="drpmnu">

         <option data-timings="something1">(01)</option>

         <option data-timings="something2">(02)</option>

</select>

JavaScript:

 $(".drpmnu").selectmenu({
    change: function( event, ui ){
        console.log($(this).data('timings'));
    }
});

http://jsbin.com/hicura/1/edit?html,console,output

1

There are 1 answers

0
Scimonster On BEST ANSWER

this refers to the selectmenu itself, not the object in it. You need to use ui.item for that:

$(".drpmnu").selectmenu({
    change: function( event, ui ){
        console.log($(ui.item.element).data('timings'));
    }
});