18 lines
455 B
JavaScript
18 lines
455 B
JavaScript
|
const tx = document.getElementsByTagName("textarea");
|
||
|
for (let i = 0; i < tx.length; i++) {
|
||
|
tx[i].setAttribute(
|
||
|
"style",
|
||
|
tx[i].getAttribute("style") +
|
||
|
";height:" +
|
||
|
(tx[i].scrollHeight + 4) +
|
||
|
"px;overflow-y:hidden;"
|
||
|
);
|
||
|
tx[i].addEventListener("change", resize_textarea, false);
|
||
|
}
|
||
|
|
||
|
function resize_textarea(t) {
|
||
|
t = t instanceof Element ? t : this;
|
||
|
t.style.height = "auto";
|
||
|
t.style.height = t.scrollHeight + 4 + "px";
|
||
|
}
|