I need one help. I need to fix the the textarea height as per the content written inside it. I am explaining my code below.
<html>
<head>
<link rel="stylesheet" href="lib/style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="lib/script.js"></script>
</head>
<body>
<h1>Hello</h1>
<textarea id="textarea-container">
Line 1
Line 2
Line 3
Line 4
ccccccccccccccccccccc
</textarea>
<script>
var $textArea = $("#textarea-container");
// Re-size to fit initial content.
resizeTextArea($textArea);
// Remove this binding if you don't want to re-size on typing.
$textArea.off("keyup.textarea").on("keyup.textarea", function() {
resizeTextArea($(this));
});
function resizeTextArea($element) {
$element.height($element[0].scrollHeight);
}
</script>
</body>
</html>
Here some text are present inside the textarea and its scrolling. I need here the text area height will expand as per the content present inside it not more than that and it never scroll.