Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy cant a mouseup event prevent a click event
    primarykey
    data
    text
    <p><a href="http://jsfiddle.net/zhAHt/1/" rel="noreferrer">jsfiddle</a></p> <pre><code>&lt;div class='wrapper'&gt; &lt;button class='child'&gt;Click me&lt;/button&gt; &lt;/div&gt; function h(e) { e.preventDefault(); e.stopPropagation(); e.stopImmediatePropagation(); alert(e.type); return false; } document.querySelector('.wrapper').addEventListener('mouseup', h, false); document.querySelector('.child').addEventListener('click', h, false); </code></pre> <p>I expect this to prevent the 'click' event from firing, but it doesn't. However, changing <code>mouseup</code> to <code>mousedown</code> does in fact prevent the click event.</p> <p>I've also tried setting the <code>useCapture</code> argument to true, and that also doesn't produce the desired behavior with <code>mouseup</code>. I've tested this on Chrome and Firefox. Before I file bugs, I figured I'd ask here.</p> <p>Is this a bug in current browsers, or is it documented behavior?</p> <p>I've reviewed the <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-flow" rel="noreferrer">W3C standard (DOM level 2)</a>, and I wasn't able to find anything that could explain this behavior, but I could have missed something.</p> <p>In my particular case, I'm trying to decouple two pieces of code that listen to events on the same element, and I figured using capture events on the part that has priority would be the most elegant way to solve this, but then I ran into this problem. FWIW, I only have to support officially supported versions of FF and Chrome (includes ESR for FF).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload