ItSolutionStuff.com

Textarea Auto Height Based on Content Jquery Example

By Hardik Savani • September 5, 2020
jQuery

In this example, you will learn textarea auto height based on content jquery. if you want to see example of resize textarea to fit content then you are a right place. you can see auto resize textarea jquery. step by step explain auto expand textarea jquery. follow bellow step for auto adjust textarea height jquery.

If you need to set textarea auto height based on content using jquery then i will help you how to auto resize height of textarea in jquery. i will give you two examples of auto adjust textarea height using jquery.

So, let's see bellow preview and examples:

Preview:

Example 1:

<!DOCTYPE html>

<html>

<head>

<title>Textarea Auto Height Based on Content Jquery</title>

<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>

</head>

<body>

<h1>Textarea Auto Height Based on Content Jquery Example - ItSolutionStuff.com</h1>

<strong>Body:</strong>

<br/>

<textarea id="body" style="width: 400px;"></textarea>

<script type="text/javascript">

$('#body').on('input', function () {

this.style.height = 'auto';

this.style.height = (this.scrollHeight) + 'px';

});

</script>

</body>

</html>

Example 2:

<!DOCTYPE html>

<html>

<head>

<title>Javascript Auto-resize Textarea as User Types Example</title>

</head>

<body>

<h1>Javascript Auto-resize Textarea as User Types Example - ItSolutionStuff.com</h1>

<strong>Body:</strong>

<br/>

<textarea id="body" style="width: 400px;"></textarea>

<script type="text/javascript">

textarea = document.querySelector("#body");

textarea.addEventListener('input', autoResize, false);

function autoResize() {

this.style.height = 'auto';

this.style.height = this.scrollHeight + 'px';

}

</script>

</body>

</html>

I hope it can help you...

Tags: jQuery
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

Angular Material Textarea Tutorial

Read Now →

How to Set Maxlength for Textarea in Javascript?

Read Now →

JQuery Prevent Submit Form on Enter Key Except Textarea Example

Read Now →

How to Remove All Whitespace from String in JQuery?

Read Now →

JQuery Delete Confirm Modal using Bootbox Example

Read Now →

How to Get Attribute Value in JQuery?

Read Now →

How to Each Loop with Class Element in JQuery?

Read Now →

How to Remove Query String from URL using JQuery?

Read Now →

Automatically Scroll to Bottom of Div JQuery Example

Read Now →

Check and Uncheck All Checkbox using JQuery Example

Read Now →