Thursday, March 24, 2011

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?

From stackoverflow
  • 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.

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

0 comments:

Post a Comment