I have this code which is working. But it is only for one textarea because it uses ID. However i would like to use this for all textareas that on my code. I have tried getElementsByClassName but it didn't work.
HTML:
<textarea id="textarea1" class="form-control page-textarea" rows="4" style="height:92px;" name="memory" placeholder="new comment..."></textarea>
JS:
<script type="text/javascript">
var textarea = document.getElementById("textarea1");
var limit = 200;
textarea.oninput = function() {
textarea.style.height = "";
textarea.style.height = Math.min(textarea.scrollHeight, limit) + "px";
if(textarea.style.height == "92px"){
textarea.style.overflow = "hidden";
} else if(textarea.style.height < limit + "px"){
textarea.style.overflow = "hidden";
} else {
textarea.style.overflow = "auto";
}
};
</script>
How do i do this?