Checking for change() firing on page load.

by clarusdignus

HTML

a: <input type="text" id="a" value="x" />
b: <input type="text" id="b" value="y" />

JavaScript

// Apply value of #a to #b and fire change event...
$('#b').val($('#a').val()).change();

// Listen for the change and alert...
$('#b').on('change', function() {
    alert("Change event fired on load.");
});