What is the best autogrow textarea plugin for jQuery?

There seem to be a ton of really bad autogrow textarea plugins for jQuery. I want my autogrowing text box to be as good as Facebook's. I want it to fit the current line only, and add a line right before it's needed.

Most of the plugins I've reviewed try to guess line height from number of characters, which seems too naive. I've read one solution that creates a hidden div to calculate height. That seems like the right path, but that solution wasn't in plugin form.

What's out there that does what I want and is easy to install?

Answers


Try it. http://www.jacklmoore.com/autosize I thing here's the best. It's a very good one.


I have a plugin that calculates just that: http://www.mostthingsweb.com/2012/01/textarea-line-count-version-1-3-released/. It uses the hidden div approach, and even matches the correct font attributes. Check it out :)

You could invoke the plugin every time a user hits a key in the textbox, and then resize the textbox accordingly. Maybe even every other key, if you want to not hog processing power.


hey this is pure javascript

function sz(t) {
    dv = document.createElement("div");
    dv.style.visibility="hidden";
    dv.style.position="absolute";
    dv.style.width=t.offsetWidth;
    dv.innerHTML = t.value.replace(/\n/g, "<br>");
    document.body.appendChild(dv);
    t.style.height=(dv.offsetHeight+22)+"px";
    dv.parentNode.removeChild(dv);
}

then you just use onkeyup="sz(this)"


Need Your Help

UIButton scale on touch?

iphone ipad animation uibutton scale

Can someone tell me how I can scale an UIButton on touch? The button should scale up like 10%.

C# - WCF - inter-process communication

c# .net wcf process

What is the best WCF binding to use for inter-process communication?