views:

1456

answers:

2

I'd like to increase the height of a textarea when the text wraps to a new line, so it dynamically expands to whatever it needs to be. I don't want to use the onscroll event because I want the expansion to always be one step ahead of the scrolling, so the textarea never scrolls until it reaches a max height of x.

Anyway I could do this?

A: 

I dont know of any event that happens on wrap, you might be able to just use a keypress or change function and count the characters entered since the last wrap, and if it's over a given amount you can increase the size of the textarea.

John Boker
+2  A: 

Numerous plug-ins already exist that do this. They probably don't do the maxheight deal, but you could add that in:

if ($(this).height() >= maxHeight) {
  return false;
}
Jonathan Sampson