At the moment I am creating a jQuery plugin.
I am facing a problem when using a callback.
$.fn.bondye = function (options) {
var settings = $.extend({
callback: function () {}
}, options);
return this.each(function () {
$(this).addClass('test');
settings.callback();
});
};
$(".myDiv").bondye({
callback: function () {
$(this).removeClass("test");
}
});
jsFiddle example: http://jsfiddle.net/HEJtm/1/
But I aint able to do anything with the div within the callback.
I used http://learn.jquery.com/plugins/advanced-plugin-concepts/ to learn developing jQuery plugins, but I cannot find anything about callbacks.
You need to set the context for your callback. You can use call
:
settings.callback.call(this);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With