(function($){ $.fn.extend({ elastic: function() { var mimics = new Array('paddingTop','paddingRight','paddingBottom','paddingLeft','fontSize','lineHeight','fontFamily','width','fontWeight'); return this.each(function() { if(this.type == 'textarea') { var textarea = $(this); var marginbottom = parseInt(textarea.css('lineHeight'))*2 || parseInt(textarea.css('fontSize'))*2; var minheight = parseInt(textarea.css('height')) || marginbottom; var goalheight = 0; var twin = null; function update() { if (!twin) { twin = $('
').css({'display': 'none','position': 'absolute'}).appendTo('body'); $.each(mimics, function(){ twin.css(this,textarea.css(this)); }); } var content = textarea.val().replace(/<|>/g, ' ').replace(/\n/g, '