Logan Serman
Logan Serman

Reputation: 29870

jQuery- Call function when textarea wraps to a new line?

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?

Upvotes: 2

Views: 2079

Answers (3)

TunaFFish
TunaFFish

Reputation: 11302

I just decided to use this plugin: http://blogs.sitepointstatic.com/examples/tech/textarea-expander/demo.html

Upvotes: 0

Sampson
Sampson

Reputation: 268344

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;
}

Upvotes: 2

John Boker
John Boker

Reputation: 83709

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.

Upvotes: 0

Related Questions