autoTextarea.js 669 Bytes
$(function(){
    var autoHeight = 0;
    var autoWidth = 0;
    $('textarea').focus(function(){
        autoHeight=$(this).prop("scrollHeight");
        autoWidth=$(this).width();
    });
    $('textarea').bind('input propertychange', function() {
        $(this).after('<textarea class="autoHeight" style="height:'+autoHeight+'px;width:'+autoWidth+'px;visibility:hidden;"></textarea>');
        $('.autoHeight').val($(this).val());
        if($(this).next().attr('class') == "autoHeight"){
            $(".autoHeight").not(":first").remove();
        }
        var height = $('.autoHeight').prop("scrollHeight");
        $(this).css('height',height+'px');
    });
});