TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

JavaScript useCapture demystified

17 pointsby benhowdle89over 12 years ago

3 comments

jonchangover 12 years ago
quirksmode has more historical background and actually explains what happens during capture and bubble and when you might want to use it.<p><a href="http://www.quirksmode.org/js/events_order.html" rel="nofollow">http://www.quirksmode.org/js/events_order.html</a>
评论 #5317662 未加载
评论 #5318015 未加载
jdlshoreover 12 years ago
"When an event is attached to an element, it will fire once the event has fully bubbled up to the document."<p>This is not quite correct. The event will fire <i>as</i> it bubbles upward, not <i>after</i> it reaches the document level.<p>The DOM Events Level 3 specification has a helpful diagram:<p><a href="http://www.w3.org/TR/DOM-Level-3-Events/#event-flow" rel="nofollow">http://www.w3.org/TR/DOM-Level-3-Events/#event-flow</a><p>There's also the "browser default" behavior, which is stuff like highlighting selected text. That <i>does</i> happen after the event finishes bubbling. (Usually.)<p>Note that stopping an event from bubbling (with `event.stopPropagation()`) and stopping an event's default behavior (with `event.preventDefault()`) are two separate, unrelated actions. However, returning false from an event handler is equivalent to doing both.
benhowdle89over 12 years ago
So far, feedback has been:<p>1. maybe an initial syntax overview: target.addEventListener(type, listener[, useCapture]);<p>2. I think it’d be worth explaining what capture and bubble are.<p>I agree!
评论 #5317588 未加载