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 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 add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Aug 15 Is PHP still good for back-end programming? #Aug 10 How to create a multisite network in WordPress? #Aug 3 How to create a circle that follows a cursor using JavaScript and CSS? #Aug 3 How to make a curtain slider using jQuery and CSS? #Aug 2 How to progressively load images and add a blurry placeholder? #Aug 1 How to create a placeholder loader (throbber) using CSS?
You might also like these
Pagination in CSS with multiple examplesCSSCSS Overflow Property with ExamplesCSSHow to create a simple slider with CSS and jQuery?CSSKanban vs Scrum: The two frameworks of agile principlesMiscellaneousHow to change value of a span tag using a reference from another div using jQuery?jQueryFULL OUTER JOIN in PostgresPostgresThe Difference Between the echo and print Commands in PHPPHPHow to get ACF values from custom post type?WordPressShould we ever delete data from a database?MiscellaneousHow to check if the element exists using JavaScript and jQuery?JavaScriptDifference between :where and :is in CSSCSSList of WordPress directories functionsWordPress