Autoresize textarea remove lines in backspace
I have the following code to autoresist a textbox:
HTML:
<textarea class="autoresize" id="txt" rows="2"></textarea>
JS:
$('#txt').keydown(function(e) {
var $this = $(this),
rows = parseInt($this.attr('rows'));
// on enter, add a row
if (e.which === 13)
$this.attr('rows', rows + 1);
// on backspace, remove a row -- THIS IS THE PROBLEM
if (e.which === 8 && rows !== 2)
$this.attr('rows', rows - 1);
});
This works well, but when I press backspace to erase a letter from a word, it also deletes lines and that's my problem.
I want it to shrink when the user "deletes" blank lines, but I don't know how to achieve it.
If you want, you can check it out in this script .
+3
source to share