3

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

alokrajiv
  • 1,038
  • 1
  • 8
  • 7

1 Answers1

5

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'));
    }
});
Scimonster
  • 32,893
  • 9
  • 77
  • 89