JSFiddle - React, Tailwind, and code Playground
HTML
<div id="foo">asd</div>
JavaScript
;
(function($, window, document, undefined) {
var pluginName = 'test';
var defaults;
function Plugin(element, options) {
this.element = element;
this.options = $.extend({}, defaults, options);
this._name = pluginName;
this.init();
}
Plugin.prototype = {
init: function(name) {
this.hello();
},
hello: function(name) {
console.log('hello');
},
goodbye: function(name) {
console.log('goodbye');
}
}
$.fn[pluginName] = function(options) {
return this.each(function() {
if (!$.data(this, 'plugin_' + pluginName)) {
$.data(this, 'plugin_' + pluginName, new Plugin(this, options));
}
else if (Plugin.prototype[options]) {
$.data(this, 'plugin_' + pluginName)[options]();
}
});
}
})(jQuery, window, document);
$(document).ready(function() {
$("#foo").test();
$("#foo").test('goodbye');
});