How can I resize the text area so that it fits the content width and set the minimum and maximum width?
P粉277824378
P粉277824378 2023-09-05 11:21:30
0
1
516

So, I'm having trouble now with the text area, I can't resize it to the content width... I found a long and detailed answer about content height and it works! But there is no content width above...

This is that article: Creating a text area with automatic resizing

However, my problem is not solved, I need to adjust the width too. Consider maximum and minimum widths.

This is sample code:

$("textarea").each(function () { this.setAttribute("style", "height:" (this.scrollHeight) "px;"); }).on("input", function () { this.style.height = 0; this.style.height = (this.scrollHeight) "px"; }); $("textarea").trigger("input");
textarea{ border: 1px solid black; min-width: 50px; max-width: 300px; width: auto; }