javascript - Automatically setting the height of a textarea -


i have textarea want height increase automatically, doesn't work, here jquery:

$('.flat_textarea').delegate( 'textarea', 'keyup', function (){    $(this).height( 30 );    if(this.scrollheight>30)   $(this).height(this.scrollheight); });  $('.flat_textarea').find( 'textarea' ).keyup();  $('.flat_textarea textarea').on("keyup",function (){   $(this).height( 30 );   if(this.scrollheight>30)      $(this).height(this.scrollheight); }); 

html:

<form method="post" class="flat_textarea" >     <textarea></textarea> </form> 

use on() instead of delegate() (delegate() deprecated) - , keypress() instead of keyup().

here working jsfiddle.

change code following:

$('.flat_textarea').on('keypress', 'textarea', function (){    $(this).height(30);    if(this.scrollheight > 30)       $(this).height(this.scrollheight); });  $('.flat_textarea').find('textarea').keypress();  $('.flat_textarea textarea').on("keypress", function (){   $(this).height(30);   if(this.scrollheight > 30)      $(this).height(this.scrollheight); }); 

Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -