How can I make a textarea automatically expand using jQuery?
I have a textbox for explaining the agenda of the meeting, so I want to expand that textbox when my agenda's text keep growing that textbox area.
ベストアンサー1
If you dont want a plugin there is a very simple solution
$("textarea").keyup(function(e) {
while($(this).outerHeight() < this.scrollHeight + parseFloat($(this).css("borderTopWidth")) + parseFloat($(this).css("borderBottomWidth"))) {
$(this).height($(this).height()+1);
};
});
See it working in a jsFiddle I used to answer another textarea question here.
To answer the question of doing it in reverse or making it smaller as text is removed: jsFiddle
And if you do want a plugin