pravin
pravin

Reputation: 2155

Call a function on any event of textarea

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

Upvotes: 1

Views: 396

Answers (2)

Pranay Rana
Pranay Rana

Reputation: 176886

Try something like this :

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

                            $(element).bind({

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

                        }
   );

Upvotes: 1

Sarfraz
Sarfraz

Reputation: 382616

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

Upvotes: 0

Related Questions