Created
May 29, 2023 19:31
-
-
Save jasjs1/1ed827702092f4716ebe64c7e9e13127 to your computer and use it in GitHub Desktop.
Make HTML textarea size adapt to the amount of text that is in the textarea
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const textarea = document.getElementById('example-element'); // Replace example-element with the ID of your HTML textarea element. | |
textarea.addEventListener('input', function() { | |
this.style.height = 'auto'; | |
this.style.height = this.scrollHeight + 'px'; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment