$('#s') is an input textfield. After typing in the textfield (for example 'a'), select an item (for example 'abc') from the autocomplete menu, the change function is executed and variable v becomes 'a'. It seems autocomplete triggers a change event for the textfield before changing its value. The correct behavior should be triggering the event after changing the textfield value.