Yogesh Chauhan's Blog

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

in JavaScript & jQuery on 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

Checkout the demo:

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


Most Read

#1 Solution to the error “Visual Studio Code can’t be opened because Apple cannot check it for malicious software” #2 How to add Read More Read Less Button using JavaScript? #3 How to check if radio button is checked or not using JavaScript? #4 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #5 How to uninstall Cocoapods from the Mac OS? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

#Apr 8 JSON.stringify() in JavaScript #Apr 7 Middleware in NextJS #Jan 17 4 advanced ways to search Colleague #Jan 16 Colleague UI Basics: The Search Area #Jan 16 Colleague UI Basics: The Context Area #Jan 16 Colleague UI Basics: Accessing the user interface
You might also like these
Forcing the domain to serve securely using HTTPSMiscellaneousSubquery in PostgresPostgres5 Steps to Create a Line using Canvas Tag in HTML5HTMLAngular 9 time clock update every minute, second, hourAngularAlways add associated labels to your Form elementsUI/UXHow to use $IF operator in Envision Basic?Envision BasicLearn to Implement Estimated Reading Time using PHP Part 2: Final Implementation with Source CodePHPMIN, MAX, COUNT, AVG and SUM in SQLSQL/MySQLThe basics of CSS Box modelCSS@mixin and @include in SCSS (Sass)SCSSWhat is PostgreSQL? How similar or different it is from SQL?PostgresHow to read Standard Input in Swift?Swift