javascript – Textarea auto expand when resizing browser window

html - Animation after toggling doesn't apply the second style

I want to create a textarea that expands or contracts to fit the content as the browser window is resized. Here’s what I have now, with reference to textareas that expand with content input:

var tx = document.getElementsByTagName("textarea");
for (let i = 0; i < tx.length; i++) {
  tx[i].setAttribute("style", "height:" + (tx[i].scrollHeight) + "px;overflow-y:hidden;");
  window.addEventListener("resize", autoResize(tx[i]));

function autoResize(el) { = "auto"; = (this.scrollHeight) + "px";

How do I get this to work?

Source link

Leave a reply

Please enter your comment!
Please enter your name here