Textarea Resize JavaScript: Resize textarea using jQuery plugin

textarea-resize-javascript-jquery Have you ever used textarea in your UI design to get text from user? (Ofcourse you must) :) You must have specified rows and cols attribute to define the height and width of the textarea, or by using CSS. By whatever mean you create your textarea, the width and height of the textarea is fixed. What if you want your user to change the width and height of the textarea or resize the textarea while she is entering the text? You can simply do this by using following JavaScript. Actually this is a jQuery plugin that lets you resize the textarea at runtime. Let us assume that following is your HTML code:
<html> <head> <title>jQuery textarea resizer plugin</title> <script type="text/javascript" src="//code.jquery.com/jquery-latest.js"></script> <script type="text/javascript" src="jquery.textarearesizer.compressed.js"></script> <script type="text/javascript"> /* jQuery textarea resizer plugin usage */ $(document).ready(function() { $('textarea.resizable:not(.processed)').TextAreaResizer(); }); </script> <style type="text/css"> div.grippie { background:#EEEEEE url(grippie.png) no-repeat scroll center 2px; border-color:#DDDDDD; border-style:solid; border-width:0pt 1px 1px; cursor:s-resize; height:9px; overflow:hidden; } .resizable-textarea textarea { display:block; margin-bottom:0pt; width:50%; height: 30%; } </style> </head> <body> <h1>jQuery TextAreaResizer plugin example</h1> <h2>Simple textarea + Resizer bar (grippie)</h2> <textarea rows="5" class="resizable">some test text some test text some test text some test text some test text some test text </textarea> </body> </html>
Code language: HTML, XML (xml)
In the above code the textarea is made re-sizable by using jQuery plugin. All you have to do is to include jquery.textarearesizer.js in your HTML document where you have the textarea and call .TextAreaResizer(); method.
$('textarea.resizable:not(.processed)').TextAreaResizer();
Code language: JavaScript (javascript)
Notice that we have passed class name .resizable in the jquery call $() and then called TextAreaResizer() method.

Demo

Click here to view online demo.

Download

Click here to download textarearesizer plugin.
Get our Articles via Email. Enter your email address.

You may also like...

10 Comments

  1. Felix says:

    Great!, usefull. Thanks!

  2. Thanks for the comment Felix. Feel free to subscribe for RSS feed for more such articles from viralpatel.net :)

  3. Aki says:

    Hi there,

    I’ll give it a try, sounds very useful :)
    Thanks a lot for this jquery plugin.

  4. naren says:

    thank you… working good…

  5. nux says:

    Is there any option to have grippie on the right side for horizontal resizing?

  6. Beehand says:

    Thanks, work great! :)

  7. amazing says:

    thank you… working good…good job :)

  8. Hello Viral Patel, thank you for your work. Ist works great with my own WordPress Themes. I have placed the CSS as a separate file, and specified in the header.

  9. Bala says:

    nice plugin thanks a lot

Leave a Reply

Your email address will not be published. Required fields are marked *