I want to auto resize the textarea width when I write inside it, with a max-width, like this code do for the input. http://jsbin.com/ahaxe it's possible?
Asked
Active
Viewed 2.0k times
1
-
maybe using em in your wisth. it represents the width on an M. will not be very precise but it could work. – Louis Loudog Trottier Oct 31 '12 at 09:53
-
Duplicate : http://stackoverflow.com/questions/2948230/auto-expand-textarea – Pranav 웃 Oct 31 '12 at 09:54
3 Answers
2
DEMO : http://jsfiddle.net/buM6M/1/
html:
<textarea id="t1" style='min-width:100px;min-height: 100px'>
</textarea>
<div id="d1" style='max-width:200px;min-height:20px;display: none'>
</div>
js code :
$("#t1").live({
keyup: function(e){
$("#d1").text($(this).val());
$(this).css("width", $("#d1").css("width"));
$(this).css("height", $("#d1").css("height"));
}
});
Set the dimensions of the div and textarea as per your requirement .

user1305989
- 3,231
- 3
- 27
- 34
0
use jquery autogrow plugin.
download autogrowtextarea.js and add to script
and add this css in head:
#id_of_textarea
{
height:auto;
width:width_of_textarea_you_want
}
$(function() {
$('#id_of_textarea').autogrow();
});
for avoiding scroll:
$('#id_of_textarea').css('overflow', 'hidden').autogrow()

Milind Anantwar
- 81,290
- 25
- 94
- 125