-
Notifications
You must be signed in to change notification settings - Fork 536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
trigger & dispatchEvent #38
Comments
Thanks! The only good thing is that, with half a day of searching the web and reading articles, I'm now so impressed of those differences and mechanisms... |
how to pass token in dispatch event? |
Hi, The "Trigger Native" code uses |
updated @ 2014/02/04
trigger & dispatchEvent are different
Don't replace $.trigger & dispatchEvent simply.
FIrst,
$.trigger
does browser default actions if possible.dispatchEvent
does not. It simply dispatches event object.(
new Event
anddocument.createEvent('HTMLEvents')
are the same. I'm usingnew Event
just because it's short.)Basically, created events by script do not trigger browser default actions.
Click event is special.
new MouseEvent("click")
does browser default click.http://www.w3.org/TR/DOM-Level-3-Events/#trusted-events
Expample
click
replaceable
not replaceable
replaceable
other
replaceable
not replaceable
demo:
http://jsfiddle.net/uS636/1/
Second, $.trigger runs on all matched elements.
In pure JS,
There are many other differences.
So you can't replace $.trigger & dispatchEvent that simply.
Trigger Custom / Trigger Native
Eventlistener does not see event interface.
Eventlistener just responds to
event.type
.The following two event object invoke Eventlistener's callback.
Demo:
http://jsfiddle.net/McZpC/2/
change
event has no default action. There are no difference between dispatching (a)Event whose type is change and (b)CustomEvent whose type is changeBut when the event type is click, there IS a difference.
So it's not appropriate to use 'change' event as Trigger Native example.
Solution(i remove this section. it was not correct, sorry)
The text was updated successfully, but these errors were encountered: