keldar
keldar

Reputation: 6242

jQuery input event - trigger('change') does not it

I have the following event listener on my inputs on a HTML page:

$('input').on('input', function (e) {
    console.log(this.value);
});

I understand the input event captures the following individual events change, keyup and paste.

When I update an input value using jQuery, I want to trigger this event so my event code runs. If I run:

//Does not work
$('input').val('test').trigger('change');

My event does not fire. I expected the input event handler to catch the change event. If I run:

//Does work
$('input').val('test').trigger('input');

This does work... why does triggering the change event not fire my input event handler?

Upvotes: 1

Views: 256

Answers (1)

Evan Knowles
Evan Knowles

Reputation: 7501

I expected the input event handler to catch the change event.

That's where you went wrong - the input event handler does not catch change events.

Upvotes: 3

Related Questions