1

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?

7
  • 1
    No, oninput event does not responds to onchange event. They are different. It would be really confusing world where one events trigger other events. Commented May 8, 2015 at 12:13
  • jsfiddle.net/arunpjohny/e0xr8u0x/1 - input event does fire Commented May 8, 2015 at 12:14
  • 1
    check this may be helpful to you Commented May 8, 2015 at 12:14
  • "why does triggering the change event not fire my input event handler?" Why the hell would one type of event fire another type of event? Commented May 8, 2015 at 12:26
  • 1
    @keidar it does not. If you paste something in the field, or if you type a key that will alter the text, and that will trigger an input event. Commented May 8, 2015 at 12:36

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I thought it does? Which events does it catch then?
input event caches the input event. Period

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.