Tutorial Details

How to make textarea auto resize using Javascript
09 Jun

How to make textarea auto resize using Javascript

Hi Guys,

In this tutorial, we will learn How to make textarea auto resize using Javascript. I will tell you the code for using a way to make textarea auto-resize using Javascript.

Let's look at a quick example that should help:

Example:

<!DOCTYPE html>
<html>
<head>
    <title>How to make textarea auto resize using Javascript</title>
</head>
<body>
  
<h1>How to make textarea auto resize using Javascript - omcodingtutorial.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 guys...

0 Comments

Leave a Comment