Hi Dev,
In this blog,I will learn you how to create textarea auto height based on content useing Jquery.we will show example of jquery textarea auto height based on content. 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.
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.
Example: 1Example:2
<!DOCTYPE html>
<html>
<head>
<title>Javascript Auto-resize Textarea as User Types Example - nicesnippets.com</title>
</head>
<body>
<h1>Javascript Auto-resize Textarea as User Types Example</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>
<!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 - nicesnippets.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>
It will help you...
Comments