Given the dom structure as below:
Both element1 and element2 have an onClick handler, If the user click element2, which event handler fires first?
Two Event Models:
In the old days, Netscape and Microsoft came to different conclusions:
- Netscape said that the event on ele1 takes first. This is so called Event Capturing.
- Microsoft maintained that the event on ele2 takes precedence. This is so called Event Bubble.
Event Capturing
The handler that binds on ele1 fires first, while ele2’s last.Event Bubbling
The handler that binds on ele2 fires first, while ele1’s last.W3C Models
In w3c event model, Any event is first captured until it reaches the target element, and then bubbles up again.
近期评论