Textarea expand its width while the user is typing - Javascript jQuery

Javascript examples for jQuery:Form Textarea

Description

Textarea expand its width while the user is typing

Demo Code

ResultView the demo in separate window


<html>
 <head> 
  <script src="https://code.jquery.com/jquery-2.1.1.min.js"></script> 
 </head> //w ww. ja va2  s.  c  o  m
 <body> 
  <textarea class="my" type="textarea" data-minwidth="100"></textarea> 
  <script>
$(".my").keypress(function() {
      var newWidth = ($('.my').val().length)*10;
      if(newWidth > $(".my").data('minwidth')){
           $('.my').width(newWidth);
      }
});

      </script>  
 </body>
</html>

Related Tutorials