javascript - Textarea increase ++ one row on enter and keypress using .attr() update -
i have textarea on want increase height 1 row on every enter , on each time when text goes row wile typing. have 3 conditions, when displayed want number used rows , set rows height based on this:
one: var countrows = $("textarea").val().split(/\r|\r\n|\n/).length;
two: when
keypress == 13
usedand three: when text goes row wile typing
till have achived not working :|
var countrows = $("textarea").val().split(/\r|\r\n|\n/).length; var keynum = 13; //enter keynum //for default state //not calculating $("textarea").attr("rows", countrows + 1); //for enter key //not working $("textarea").on('keypress', keynum, function() { $(this).attr("rows", countrows + 1); // alert("jjj"); }); //for case whentext goes row wile typing
i want using .attr() , updating attribute "rows" when 1 more row added or removed.
from https://stackoverflow.com/a/10080841/4801673
$("textarea").keyup(function(e) { while($(this).outerheight() < this.scrollheight + parsefloat($(this).css("bordertopwidth")) + parsefloat($(this).css("borderbottomwidth"))) { $(this).height($(this).height()+1); }; });
Comments
Post a Comment