Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  6] [ 4]  / answers: 1 / hits: 63586  / 14 Years ago, thu, february 10, 2011, 12:00:00

I have a Textarea where users can input text. By default it has a height of 17px. However if users insert a large amount of text, I want the text area to expand accordingly. Is there a way to do this with CSS ? Thanks in advance!!


More From » jquery

 Answers
60

This cannot be done with CSS alone. try the autogrow jquery plugin.
https://github.com/jaz303/jquery-grab-bag/blob/master/javascripts/jquery.autogrow-textarea.js



You can also see autogrow demo here http://onehackoranother.com/projects/jquery/jquery-grab-bag/autogrow-textarea.html



It's lightweight and easy to use. Here's how it's done. Define your textarea id. Include the jquery js file before </body>. Then between script tags, issue the jquery command $(#txtInput).autoGrow();



<body>
<textarea id=txtInput></textarea>
<script src=http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js type=text/javascript></script>

<script>
$(#txtInput).autogrow();
</script>
</body>

[#93803] Tuesday, February 8, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
darennevina

Total Points: 422
Total Questions: 128
Total Answers: 105

Location: Comoros
Member since Tue, Mar 14, 2023
1 Year ago
;