0

I am trying to use Javascript to shrink and grow automatically as the height of the scroll is increasing. The growing the height of textarea is achieved but when I am deleting the texts I can't figure out how to shrink the size.... I don't want to use the jQuery functions.

My code is:

<html>
<head>
  <script>

   function func() {
    var ta = document.getElementById('mytexta');
    ta.value+=ta.scrollHeight+' '+ta.clientHeight;
    if(ta.scrollHeight>ta.clientHeight)
      {
        ta.style.overflow='hidden';
        ta.rows+=1;
      }

                    }
  </script>
</head>
<body>
   <textarea class="mytext" onkeyup="func()" id="mytexta" style="overflow:hidden;">Here we go</textarea>
  </body>
  </html>
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Iftikhar Ali Ansari
  • 1,650
  • 1
  • 17
  • 27

0 Answers0