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

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


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.


bind is deprecated. Use on:

$("#textarea").on('change keyup paste', function() {    // your code here});

Note: The code above will fire multiple times, once for each matching trigger-type. To handle that, do something like this:

var oldVal = "";$("#textarea").on("change keyup paste", function() {    var currentVal = $(this).val();    if(currentVal == oldVal) {        return; //check to prevent multiple simultaneous triggers    }    oldVal = currentVal;    //action to be performed on textarea changed    alert("changed!");});

jsFiddle Demo


Use an input event.

var button = $("#buttonId");$("#textareaID").on('input',function(e){  if(e.target.value === ''){    // Textarea has no value    button.hide();  } else {    // Textarea has a value    button.show();  }});