I’m working on a jQuery plugin and can’t seem to override the default settings, here’s a snippet of the plugin.
$.Auction = {
defaults: {
parentId: '#span',
bidButtonClassName: '.live_bid'
}
};
$.setAuction = function(options){
startAuction();
}
function startAuction(){
var options = $.extend({}, $.Auction.defaults, options);
alert(options.parentId);
}
$.setAuction({parentId: '#div'});
Basically I’m trying to override the parentId value at the bottom, but it always alerts the value #span. Any ideas what I’m doing wrong? Thanks!
You’re passing
{parentId: '#div'}as an argument to$.setAction, but you’re not actually using it. You want to do something like this:Edit: @TmEllis suggests a better way of implementing this functionality, but it can be made better still by making the defaults themselves customizable:
See this article for a more complete discussion of how to write good jQuery plugins.