textarea auto heigth onload

by thvinic

HTML

<div id="container">
   <textarea id="text">
     auto resize de altura do campo textarea
     linha 2
     linha 3
     linha 4
     linha 5
     linha 6
     linha 7
     linha 8
     ...
     ....
     .....
     ......
   </textarea>
<div>

CSS

div#container textarea {
    overflow-y: hidden; /* prevents scroll bar flash */
    padding-top: 1.1em; /* prevents text jump on Enter keypress */
}


importante o css se nao não funciona.

JavaScript

$(document).ready ( function(){
// auto adjust the height of
$('#container').on( 'keydown', 'textarea', function (e){
    $(this).css('height', 'auto' );
    $(this).height( this.scrollHeight );
});
$('#container').find( 'textarea' ).keydown();
});