xxxxxxxxxx
const tx = document.getElementsByTagName("textarea");
for (let i = 0; i < tx.length; i++) {
tx[i].setAttribute("style", "height:" + (tx[i].scrollHeight) + "px;overflow-y:hidden;");
tx[i].addEventListener("input", OnInput, false);
}
function OnInput() {
this.style.height = 0;
this.style.height = (this.scrollHeight) + "px";
}
xxxxxxxxxx
//html
<textarea name="text" oninput="auto_grow(this)"></textarea>
//js
<script>
function auto_grow(element) {
element.style.height = "auto";
element.style.height = (element.scrollHeight)+"px";
};
const x = document.querySelector('#textarea-input')
x.onsubmit = (event) => {
messageBox.style.height = 'auto';}
</script>
xxxxxxxxxx
function addAutoResize() {
document.querySelectorAll('[data-autoresize]').forEach(function (element) {
element.style.boxSizing = 'border-box';
var offset = element.offsetHeight - element.clientHeight;
element.addEventListener('input', function (event) {
event.target.style.height = 'auto';
event.target.style.height = event.target.scrollHeight + offset + 'px';
});
element.removeAttribute('data-autoresize');
});
}
xxxxxxxxxx
function autoResize() {
console.log('resizing');
textInput.style.height = (textInput.scrollHeight) + 'px';
}