var counter=0; (function func(){ if(++counter>20) return; textarea.value += "\nТекст"; setTimeout(func,2*1000); })();