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

android - net_scheduler holding wakelock -

sql - MySQL : Getting Entries from a many-to-many table -

java - Retrieving data from database using jsp (Hibernate + Spring + Maven) -