How can I bind to the change event of a textarea in jQuery?

Lolly picture Lolly · Jul 5, 2012 · Viewed 264.7k times · Source

I want to capture if any changes happened to <textarea>. Like typing any characters (deleting,backspace) or mouse click and paste or cut. Is there a jQuery event that can trigger for all those events?

I tried change event, but it triggers the callback only after tabbing out from the component.

Use: I want to enable a button if a <textarea> contains any text.

Answer

Blaster picture Blaster · Jul 5, 2012

Try this actually:

$('#textareaID').bind('input propertychange', function() {

      $("#yourBtnID").hide();

      if(this.value.length){
        $("#yourBtnID").show();
      }
});

DEMO

That works for any changes you make, typing, cutting, pasting.