views:

29

answers:

2

Hi folks,

I wanted to call a signle function on any event happens for <textarea>.

How do I achieves this.

Please do suggest me folks, jquery is preferable.

Thanks,

-Pravin

A: 

You can do something like this:

$('#textarea_id').change(function(){
  // your code...
});

That code will run when text of textarea changes. If you want, you can also run the code when key is pressed with keyup or keypress event:

$('#textarea_id').keypress(function(){
  // your code...
});
Sarfraz
+1  A: 

Try something like this :

$("textarea").each(
                        function(element) {

                            $(element).bind({

                                focusin: function() {
                                    $(this).toggleClass('ui-state-focus');
                                },
                                focusout: function() {
                                    $(this).toggleClass('ui-state-focus');
                                }
                            });

                        }
   );
Pranay Rana