Just call autoheight(htmlElement); where htmlElement is a DOM node reference to some textarea. The textarea will adjust it's height immediately and then it will do it automatically as the user types into that textarea. If for some reason you need to readjust it manually (e.g. when the value changed programatically) just call the same function again. The events listeners won't get attached twice.