So I’m converting a plugin. Originally I had a traditional javascript function with some variables I pass in, but I wanted to make it a full Jquery plugin with options. The documentation shows you how to set them up, but not how to use them in your code. Here’s a bit of the code:
jQuery.fn.placeholderRX = function(options) {
var settings = jQuery.extend({
hoverColor: '#fff',
addClass: 'null',
textColor: '#FBFBFB'
}, options);
var $this = $(this);
$this.children('.inputSpan').each(function() {
$(this).children('.inputText').hover(
function() {
$input.children('.input').css('background-color', hoverColor);
},
function() {
$input.children('.input').css('background-color', revertColor);
}
);
}
});
};
How would I pass that color option value to the hover function beneath it? Or more simply, can I just pass the option value to a variable?
You have declared a variable called
settings. You can access thehoverColorproperty of that object withsettings.hoverColor:The
optionsargument to your plugin will be an object too. When you pass that in, theextendmethod will merge the contents of theoptionsobject and the “defaults” object, and you assign the result of that merge tosettings.