$('#sub').click(function () { var self = $(this); if( oneshotbtn(self,2000,'#01b637') ){ return false; } }); function oneshotbtn(btn_el,delay,color) { oneshotbtn.submit_flag = oneshotbtn.submit_flag || false; setTimeout(function () { oneshotbtn.submit_flag = true; btn_el.css('background-color','#888'); btn_el.prop('disabled', true); }, 10); setTimeout(function () { oneshotbtn.submit_flag = false; btn_el.css('background-color',color); btn_el.prop('disabled', false); }, delay); return oneshotbtn.submit_flag; }