Hirvesh
Hirvesh

Reputation: 7982

JQuery TextArea AutoGrow Plugin

I'm trying to find the best textarea autogrow plugin. I need one which resizes the textarea even when I paste into it. Any idea?

Upvotes: 8

Views: 22563

Answers (9)

Bud Damyanov
Bud Damyanov

Reputation: 31839

Auto-expand of text area can be accomplished without plugin. For example:

 var change_textarea = function() {
   jQuery('#your_textarea').on( 'change keyup keydown paste cut', 'textarea', 
   function(){
     jQuery(this).height(0).height(this.scrollHeight);
   }).find( 'textarea' ).change();  
 }  

And do not forget to call the function on document ready:

  jQuery(document).ready(function() {
     change_textarea();
  )};

Upvotes: 0

crisc2000
crisc2000

Reputation: 1222

"I need one which resizes the textarea even when I paste into it"

this method also listen for copy/paste events: https://stackoverflow.com/a/5346855/4481831

I think on modern browsers those events can be replaced with "input" event, but on older browser this method will not work.

Upvotes: 0

Manish Trivedi
Manish Trivedi

Reputation: 3559

Why not use it?? http://plugins.jquery.com/project/autogrowtextarea

Or another updated version of this plugin here: https://github.com/ro31337/jquery.ns-autogrow

Upvotes: 4

Gaucho_9
Gaucho_9

Reputation: 265

I used the following method, in jQuery.

setInterval(function(){
      $(name_textarea).css('height', $(name_textarea)[0].scrollHeight+2+'px')
},100);

Try it, you could possibly change the scrollHeight to obtain the best results.

Upvotes: 2

Pete Montgomery
Pete Montgomery

Reputation: 4100

This is the one I ended up using. Working great so far!

http://www.jacklmoore.com/autosize/

The JQuery Elastic plugin is slow and didn't work for me in IE8.

Upvotes: 4

Andrew Dryga
Andrew Dryga

Reputation: 692

i made another one plugin to do this, check it here: https://github.com/AndrewDryga/jQuery.Textarea.Autoresize

Upvotes: 0

Brave Dave
Brave Dave

Reputation: 1300

Here is another plug, that also support horizontal growing of text areas:

https://github.com/dgbeck/jquery.autogrow-textarea

It is also based on the "mirror" approach but falls back to simple math in IE 8 and lower, since the mirror approach leads to textareas that grow too quickly in IE <= 8.

Upvotes: -1

john
john

Reputation: 11

You can try Advanced Textarea. Download from http://www.jscripts.info

  • Auto-Height Textarea
  • Returns Plain Text and HTML Content
  • Automatic URL and Email recognition
  • HTML Tags Filter

Upvotes: 1

labilbe
labilbe

Reputation: 3584

Elastic is a very good one, and it handles CTRL + V cases too.

You can visit the website and try out a demo.

Upvotes: 7

Related Questions