I’ve built my own jQuery paging plugin. See below:
$.fn.extend({
pager: function(options) {
var settings = {
pageSize: 10,
onPageChanged: function() { }
};
if (options)
$.extend(settings, options);
return this.each(function() {
// Trigger onPageChanged event
});
}
});
Which can be be called by saying:
$('#placeholder').pager({ pageSize: 20, onPageChanged: function() { alert('Page Changed!'); } });
I was wondering how to trigger the function passed in via the options within my plugin. I’m sure this is something simple but i can’t seem to find anything in the documentation to help.
I’d appreciate the help. Thanks
Try using:
You can also optionally add additional arguments to
.call()that will be passed to the function.If you wanted a true custom event that could be bound to using
$('#placeholder').on("onPageChanged",handler)later on, do this instead:and then trigger it with: