height of textarea increases when value increased but does not reduce when value is decreased

html, javascript, jquery

Solution

The minimum scrollHeight of a textarea is always going to be the height. To get an accurate scrollHeight, set the height to 1 first.

h.height(1).height(h[0].scrollHeight);

http://jsfiddle.net/aarongloege/t2vAr/

Problem

``` <body> <script type="text/javascript">$(function(){ $("textarea").live("keyup keydown",function(){var h=$(this); h.height(h[0].scrollHeight); });}); </script> <textarea style="resize:none;width:760px;height:60px; overflow:hidden;" ></textarea> </body> ``` When textarea get overflowed it get scrollbar and scrollheight which gets applied to its height but not working for decreasing textarea height as on decreasing its value length it doesnot get scrollbar

Original source