How to auto-resize textarea based on text input using JavaScript or jQuery?

March 30, 2021

All we need to do is just increase the height if the text input is beyond the height of the textarea.

We can do that using JavaScript scrollheight method.

Here’s another post on scrollHeight.

How to get the height and width of an element using JavaScript?

jQuery Solution

Check the demo out:

JavaScript Solution

We can access the textarea elements using Tag Name

Check the demo out:

There are plenty of other ways to do it as you can see in these answers on StackOverflow.


Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to uninstall Cocoapods from the Mac OS? #4 How to Use SQL MAX() Function with Dates? #5 How to add Read More Read Less Button using JavaScript? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

Apr 7 Solution for “Yarn build: Failed because of a stylelint error” Apr 7 Make sure your links have descriptive text Apr 7 How to add Laravel to WordPress using Sage theme (and install Tailwind CSS)? Apr 2 How to create a sidebar using pure CSS? Apr 1 How to switch dark and light themes using pure CSS? Apr 1 How to calculate elapsed time in JavaScript?

You might also like these

How to Commit and Rollback Changes in SQL?SQL/MySQLHow to make a Custom Login Page in WordPress?WordPressOverview of Drupal and how it worksDrupalperspective property in CSSCSSHow to create a dynamic countdown using HTML and JavaScript?HTMLHow to Make a Simple Module with a Form and Menu Link in Drupal 7.x?DrupalSELF JOIN in PostgresPostgresSolution to “TypeError: ‘x’ is not iterable” in Angular 9AngularOpen Source Security Tools for Defense SecurityMisc10 Usability Blunders to AvoidUI/UXThe substr() method in JavaScript and how it’s different from substring()JavaScriptHow to change the Login Logo in WordPress?WordPress