Jquery Plugins, Calling Functions From Other Methods
Like so many other similar questions on here, I am writing my first jQuery plugin. It's intended to take a select element and replace the options with clickable list elements, to b
Solution 1:
One way to solve this is to put your defaults
, settings
and bindOptions
function in the methods
object (or another object in the broader scope) and reference them accordingly:
var methods = {
defaults: {
clickCallback: function() {}
},
settings: {},
bindOptions: function(var1, var2, var3) {
// Stuff to bind elements
// Hit the click callback
methods.settings.clickCallback.call(this);
},
// Init method
init: function(options) {
methods.settings = $.extend({}, methods.defaults, options);
return this.each(function() {
if (element.is('select')) {
$('option', element).each(function() {
// Stuff to create list elements
// Bind click handler to the new list elements
methods.bindOptions(var1, va2, var3);
});
}
});
},
// Disable buttons method
disable: function(options) {
$(elementID).children('li')
.removeClass('disabled')
.each(function() {
methods.bindOptions(var1, var2, var3);
});
}
};
Post a Comment for "Jquery Plugins, Calling Functions From Other Methods"