Gunner Gunner - 3 months ago 6
jQuery Question

JQuery detecting Programatic change event

If i do jQuery(expr).change( function), then I can get an event function to fire when the user makes a change to the value.

Is it possible to get this to fire if it's changed programatically, ie if I call jQuery(expr).val("moo").

or if some Plain old JavaScript changes it's value?

Thanks for any help.

Answer

After you've changed the value, you can fire the event yourself, and thus calling all the 'onchange' handlers.

jQuery('#element').change();