JSFiddle - React, Tailwind, and code Playground
HTML
<div>I'm a div</div>
<div class="inactive">I'm a div too</div>
<span>I'm a span</span>
<button>Hello</button>
JavaScript
;(function($) {
// multiple plugins can go here
(function(pluginName) {
var defaults = {
color: 'black',
testFor: function(div) {
return true;
}
};
$.fn[pluginName] = function(options) {
options = $.extend(true, {}, defaults, options);
return this.each(function() {
var elem = this,
$elem = $(elem);
// heres the guts of the plugin
if (options.testFor(elem)) {
$elem.css({
borderWidth: 1,
borderStyle: 'solid',
borderColor: options.color
});
}
});
};
$.fn[pluginName].defaults = defaults;
})('borderize');
})(jQuery);
var someVarThatMayBeSet = false;
$('div').borderize({
testFor: function(elem) {
var $elem = $(elem);
if ($elem.is('.inactive')) {
return false;
} else {
// calling "parent" function
return $.fn.borderize.defaults.testFor.apply(this, arguments);
}
}
});
$('span').borderize({
color: someVarThatMayBeSet ? 'red' : $.fn.borderize.defaults.color
});
someVarThatMayBeSet = true;
$('button').borderize({
color: someVarThatMayBeSet ? 'red' : $.fn.borderize.defaults.color
});