var c = 0 $foo = $('#foo') function timedCount() { $foo.html(c) c=c+1 $foo.addClass('big') } $foo.on('transitionend', function () { console.log('789') if(!$foo.hasClass('big')){ if(c<=10){ timedCount() } else{ console.log('123') } } else{ $foo.removeClass('big') console.log('456') } }) $('#btn').on('click',function(){ timedCount() })