Re: onclick after removing element from document during onmouseup

On Sun, Feb 27, 2011 at 4:40 AM, Glenn Maynard <glenn@zewt.org> wrote:

> If an element is removed from the document during mouseup, should the click
> event still fire?
>
> Example below.  In FF3/4, when the link is clicked, no click event is
> dispatched and the link doesn't activate.  In Chrome 9, the click event
> still fires.  (This doesn't happen with keydown/keypress; for that event
> sequence, both browsers match FF.)
>
> I think Gecko's behavior makes more sense.  I can't find this in the
> spec--is this covered?
>
>
> <a href="http://www.google.com" id="test">test</a>
> <script>
> var elem = document.getElementById("test");
> elem.addEventListener("mouseup", function(e) {
>         elem.parentNode.removeChild(elem);
> }, false);
> </script>
>

Any input on this?  I've hit variants of this issue more than once.

For example, with a dropdown menu open, the user can middle-click on a menu
item to open it in a tab.  The script hides the menu on mouseup.  In WebKit
this did what was intended: the menu closed and the menu item opened in a
tab.  In Firefox it didn't: the menu was closed but the default action
didn't happen.

(I'm not overly concerned with which behavior is correct, only with the
interoperability failure that resulted.)

-- 
Glenn Maynard

Received on Monday, 9 May 2011 00:46:25 UTC