Reputation: 34152
I'm using a jquery plugin. Is there any way to get the element that plugin is attached from the plugin's functions?
I tried this
, $(this)
. but none of them worked.
$('.myelement').plugin({
something: function(){
//in here I want to access $('.myelement)
}
});
Upvotes: 1
Views: 376
Reputation: 388316
It looks like the plugin is exposing that information to the callback methods. One workaround if you are dealing with multiple elements are to loop through the element list then call the plugin for each element with a local reference which can be used in the callback
$('selector').each(function() {
var $this = $(this);
$this.plugin({
something: function() { //$this
}
});
})
Upvotes: 2