Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

catch data-attribute after jQuery selectmenu

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

like image 213
alokrajiv Avatar asked May 06 '26 07:05

alokrajiv


1 Answers

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'));
    }
});
like image 192
Scimonster Avatar answered May 08 '26 20:05

Scimonster



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!