JSFiddle - React, Tailwind, and code Playground
HTML
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
JavaScript
(function($) {
$.fn.extend({
myTestPlugin: function() {
if (this.length > 1) {
this.each(function() { $(this).myTestPlugin(); });
return this;
}
this.initialize = function() {
this.html('Replace me!');
return this;
}
this.done = function() {
$(this).html('Done!');
};
this.alsoDone = function() {
$(this).html('Also done!');
};
return this.initialize();
}
});
})(jQuery);
var $boxes = $('.box');
$boxes.myTestPlugin();
$boxes.done();