Reputation: 2688
I'm using selectize.js something like this:
$( 'select' ).selectize( {
onChange: function( value ) {
// how to get original element here?
}
} );
There's several select
elements on the page.
I want to get select
on which the event occurred inside of onChange
.
How can I do it?
Upvotes: 4
Views: 4761
Reputation: 1934
you can get all user events from onInitialize :
$('select').selectize({
onInitialize: function (selectize) {
selectize.on('change', function (value) {
var elem = this.$input[0];
console.log('on "change" event fired > ' + elem.id);
});
selectize.on('focus', function () {
console.log('on "focus" event fired');
});
selectize.on('dropdown_open', function () {
console.log('on "dropdown_open" event fired');
});
}
}
Upvotes: -1
Reputation: 816
you can use $(this)[0]
inside the onChange. Once this
is the selectize object by itself
$( 'select' ).selectize( {
onChange: function( value ) {
var obj = $(this)[0];
alert(obj.$input["0"].id);
}
} );
Here's a Fiddle
Upvotes: 10