views:

25

answers:

3

Hi,

I want to call user defined function, once <textarea> attribute values changes. Attributes like height, width and val() of <textarea> i.e. on content change.

Your suggestion are welcome!!!

Regards,

-Pravin

A: 

Textareas support a change event which fires when the focus leaves the element after the content has changed as well as keyup/down/press events.

You can't reliably detect a change that is triggered by JavaScript, so call whatever functions you would call on change in whatever function makes the change.

David Dorward
A: 

http://jsfiddle.net/qhysQ/1

This changes on keyup, if you wish to perform a function when the textarea loses focus, change 'keyup' to 'change.'

Gazler
+3  A: 

What you likely want is the change and keyup and paste events, like this:

$("textarea").bind("change keyup paste", function() {
  //this executes when the value changes
});
Nick Craver
+1 didn't know that there was an event called paste...
Sinan Y.
@Sinan - It doesn't work in *all* browsers, but might as well support the ones that do...the others will fire the `change` event when the `<textarea>` is blurred.
Nick Craver