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
How to convert an HTML radio buttons into a toggle switch using CSS?CSSHow to show and hide an element on click in React?ReactNumber Properties in JavaScriptJavaScriptContent Blocks in SCSS (Sass)SCSS2 Ways we can create an Array in JavaScriptJavaScriptSQL Right JoinSQL/MySQLHow to add and remove capabilities from a role in WordPress?WordPressHow to change perception and behavior of a person for acceptance of new systems?MiscellaneousWordPress: How to change a blog address (URL)?WordPressHow to check if a link has http or https in it in JavaScript?JavaScriptHow destructuring works in React?ReactWhat happened to your Google Analytics Tracking ID, can’t find it?Miscellaneous