I would like an alternative to using callback method inside of jQuery's .val() method (Which it clearly doesn't support). For example:
http://jsbin.com/ilahan/edit#source
$("#box").val("The New Value", function(){
  alert("It's changed now");
});
I would like an alternative to using callback method inside of jQuery's .val() method (Which it clearly doesn't support). For example:
http://jsbin.com/ilahan/edit#source
$("#box").val("The New Value", function(){
  alert("It's changed now");
});
 
    
    What's wrong with using .change ?
$("#box").val("The New Value").change(function(){
  alert("It's changed now");
});
As Vega stated in his comments, changing the val from code won't trigger the change event no matter what: .val() doesn't trigger .change() in jquery
 
    
     
    
    .val is an instant change and so there is no need for callback? Why do you need such a callback?
Below code should do the same as what you wanted from a callback on .val
$("#box").val("The New Value");
alert("It's changed now");
 
    
    Theres no need to do a call back when setting the value, as the change happens immediately. If you are looking to execute code when the field value changes, you can use:
$("#box").change(function(){
    alert('value changed');
});
