Reputation: 173
I have created a textarea that outputs custom text. I want to have it scale to fit the text if there is too much, and not have to scroll (unless the textarea is a certain height). I also do not want to be able to manually scale the textarea. How would I go about doing this? Thank you in advance.
Upvotes: 0
Views: 7405
Reputation: 328
You might want to take a look at this. Seems to be a solution for you problem. There is a jsfiddle in the accepted answer that shows the result.
To take out the most important function see below. It sets the textareas height equal to its scrollHeight.
function resize () {
var text = document.getElementById('text');
text.style.height = 'auto';
text.style.height = text.scrollHeight+'px';
}
Upvotes: 4