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
Try something like this :
$("textarea").each(
function(element) {
$(element).bind({
focusin: function() {
$(this).toggleClass('ui-state-focus');
},
focusout: function() {
$(this).toggleClass('ui-state-focus');
}
});
}
);
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...
});
精彩评论