Jeevan
Jeevan

Reputation: 3938

Is there any difference between initEvent+dispatchEvent and jquery's trigger('click')

What is the difference between creating an event using initEvent and later dispatching the event using dispatchEvent in JavaScript and using jquery's trigger('click') trigger

Upvotes: 4

Views: 2208

Answers (1)

Denes Papp
Denes Papp

Reputation: 4002

jQuery's trigger function is not the same as dispatch, see the following table from bugs.jquery.com/ticket/11047

"The trigger function should also dispatch custom events such that code using addEventListener can catch the custom event. However, that is not happening. In fact, that is the only of the 8 combinations listed below that does not work. We should fix this to allow better interoperability between jQuery event functions and W3C DOM event functions."

PASS: If you trigger a DOM event you can catch it using the bind function
PASS: If you trigger a DOM event you can catch it using the addEventListener function
PASS: If you trigger a custom event you can catch it using the bind function
FAIL: If you trigger a custom event you can NOT catch it using the addEventListener function
PASS: If you dispatch a DOM event you can catch it using the bind function
PASS: If you dispatch a DOM event you can catch it using the addEventListener function
PASS: If you dispatch a custom event you can catch it using the bind function
PASS: If you dispatch a custom event you can catch it using the addEventListener function

Upvotes: 4

Related Questions