Skip to content

Instantly share code, notes, and snippets.

@jsejcksn
Last active January 19, 2019 23:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsejcksn/8fdc3b23ec563ac4061f547d49253da1 to your computer and use it in GitHub Desktop.
Save jsejcksn/8fdc3b23ec563ac4061f547d49253da1 to your computer and use it in GitHub Desktop.
Auto-resize textarea
for (const tx of document.getElementsByTagName('textarea')) {
tx.style.setProperty('height', `${tx.scrollHeight}px`);
tx.style.setProperty('overflow-y', 'hidden');
tx.addEventListener('input', (ev) => {
ev.target.style.setProperty('height', 'auto');
ev.target.style.setProperty('height', `${ev.target.scrollHeight}px`);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment