This site will have limited functionality while we undergo maintenance to improve your experience. If an article doesn't solve your issue and you want to ask a question, we have our support community waiting to help you at @FirefoxSupport on Twitter and/r/firefox on Reddit.

Search Support

Avoid support scams. We will never ask you to call or text a phone number or share personal information. Please report suspicious activity using the “Report Abuse” option.

Learn More

Click event incorrectly associated after DOM manipulation

more options

I have a page with input elements and a span element styled as a button. I register change event handlers on the input elements, to do validation when the input values are changed. If the inputs are invalid, I add content to a div on the page to indicate the problem. I also register a click event handler on the span styled as a button.

When I edit an input then immediately click on the span (i.e. without focus leaving the input element before clicking on the span) I see:

1) mousedown on span 2) change on input 3) mouseup on input

This occurs only when I modify the DOM in the change event handler on the input. If I don't modify the DOM then I see:

1) mousedown on span 2) change on input 3) mouseup on span 4) click on span

In the first case, I see the mouseup associated with the input element rather than the span element, even though it has the same coordinates as the mousedown which is associated with the span element. Given the coordinates are within the bounds of the span element and outside the bounds of the input element, I don't understand why the mouseup is associated with the input element rather than the span element.

There is an example of this at http://jsfiddle.net/4zx8rm7c/.

I see this behaviour in Firefox 34.0.5 and Chrome 39.0.2171.95 m.

If the association of the mouseup event with the input element, despite the seemingly unrelated coordinates of the mouse event, is intended behaviour, I need to understand why this is. I have looked at COM Level-2 event specifications (briefly) and I don't see an obvious explanation.

I have a page with input elements and a span element styled as a button. I register change event handlers on the input elements, to do validation when the input values are changed. If the inputs are invalid, I add content to a div on the page to indicate the problem. I also register a click event handler on the span styled as a button. When I edit an input then immediately click on the span (i.e. without focus leaving the input element before clicking on the span) I see: 1) mousedown on span 2) change on input 3) mouseup on input This occurs only when I modify the DOM in the change event handler on the input. If I don't modify the DOM then I see: 1) mousedown on span 2) change on input 3) mouseup on span 4) click on span In the first case, I see the mouseup associated with the input element rather than the span element, even though it has the same coordinates as the mousedown which is associated with the span element. Given the coordinates are within the bounds of the span element and outside the bounds of the input element, I don't understand why the mouseup is associated with the input element rather than the span element. There is an example of this at http://jsfiddle.net/4zx8rm7c/. I see this behaviour in Firefox 34.0.5 and Chrome 39.0.2171.95 m. If the association of the mouseup event with the input element, despite the seemingly unrelated coordinates of the mouse event, is intended behaviour, I need to understand why this is. I have looked at COM Level-2 event specifications (briefly) and I don't see an obvious explanation.

Chosen solution

This forum is intended for user support, not for web development issues. Try posting at the Web Development / Standards Evangelism forum at MozillaZine. The contributors over there are more knowledgeable about web page development issues with Firefox. http://forums.mozillazine.org/viewforum.php?f=25 You'll need to register and login to be able to post in that forum.

Read this answer in context 👍 0

All Replies (1)

more options

Chosen Solution

This forum is intended for user support, not for web development issues. Try posting at the Web Development / Standards Evangelism forum at MozillaZine. The contributors over there are more knowledgeable about web page development issues with Firefox. http://forums.mozillazine.org/viewforum.php?f=25 You'll need to register and login to be able to post in that forum.