JSFiddle - React, Tailwind, and code Playground

by Mateus Fernandes de Mello

JavaScript

(function($){
    $.fn.plug = function() {
        
        var elementos = new Array();
        var id = 0;
        var xTempo = 2000;
        
        elementos.push('novo elemento e id: ' + id);
        
        $.ajax(
            // configurações do ajax
        )
         .done(function(res) {
            
			fazAlgo(elementos[id], true);
        })
         .fail(function(res) {
            
            fazAlgo(elementos[id], false);
        })
         .always(function() {
            
            setTimeout(
                function(){
                    removeElemento(elementos[id]);
                }, xTempo);
        });

		id++; // sou obrigado a encrementar pois cada elemento tem que ter um identificador diferente
        
        var plugin = this;
        return this.each(function() {
            return plugin;
        }); 
    }; 
})(jQuery);

var plug = $.fn.plug();