When onChange() triggered, the value must be changed, and input must be blur() -ed (focus moved elsewhere); therefore, it works in your first case, but not in the second.
A change event is dispatched to an element when its value changes. This event is limited to <input> , <textarea> and <select> elements. For select flags, check boxes, and radio buttons, the event is fired immediately when the user makes a selection with the mouse, but for other types of elements, the event is delayed until the element loses focus.
Link:
source share