rvera / image-picker

Image Picker is a simple jQuery plugin that transforms a select element into a more user friendly graphical interface.
http://rvera.github.com/image-picker
Other
907 stars 216 forks source link

Can't retrieve data('img-src') #126

Closed youyouk closed 6 years ago

youyouk commented 6 years ago

Hello, I'm looking for a way to get "this.data('img-src')" of a selected img. Result is always "undefined" : $("select").imagepicker({ selected: function(option){ var src = this.data('img-src'); alert(src); } });

Thank for your help / advice / reading this message :)

rvera commented 6 years ago

well, this is probably not what you expect it to be, from the docs for selected

Specify a function to be called when an option has been selected. Receives the original select as the first argument, the image picker option as the second and the original event as the third argument.

So you will need to recover a ref to whatever you want to access using those params or freeze it in the scope.