Catch data attribute after jQuery selectmenu

I can't seem to catch the data attribute after applying the jQuery UI select menu in it.

How can you 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

+3


source to share


1 answer


this

refers to the selectmenu itself, not the object. For this you need to use ui.item

:



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

      

+5


source







All Articles