Can someone tell me what the difference between the change
and input
events is?
I am using jQuery for adding them:
$('input[type="text"]').on('change', function() {
alert($(this).val());
})
It also works with input
instead of change
.
Maybe some difference in the event ordering relative to focus?
According to this post:
oninput
event occurs when the text content of an element is changed through the user interface.onchange
occurs when the selection, the checked state or the contents of an element have changed. In some cases, it only occurs when the element loses the focus. The onchange attribute can be used with:<input>
,<select>
, and<textarea>
.TL;DR:
oninput
: any change made in the text contentonchange
:<input />
: change + lose focus<select>
: change optionThe
change
event
fires in most browsers when content is changed and the element losesfocus
, basically an aggregate of changes. You will not see this fired for every single changed unlike theinput
event
.The
input
event
fires synchronously on change of the content for the element. So you will see this event occur more often. Browser support varies.