Bug 105697 - Changing HTML content of <button> onchange of an <input> prevents a click from firing
Summary: Changing HTML content of <button> onchange of an <input> prevents a click fro...
Status: UNCONFIRMED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 528+ (Nightly build)
Hardware: Macintosh OS X 10.8
: P2 Minor
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-12-23 13:55 PST by TJ VanToll
Modified: 2019-02-06 09:18 PST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description TJ VanToll 2012-12-23 13:55:51 PST
See the following code example (or see it live at http://jsfiddle.net/tj_vantoll/sNa3R/).

<!DOCTYPE html>
<html>
<head></head>
<body>

    <button>Initial</button>
    <input>

    <script>
        var button = document.getElementsByTagName('button')[0];
        var input = document.getElementsByTagName('input')[0];

        button.addEventListener('click', function() {
            alert('click');
        });

        input.addEventListener('change', function() {
            button.innerHTML = '<span>Changed</span>';
        });
    </script>

</body>
</html>

1) Type something in the textbox.
2) Without losing focus from the textbox click the button with the mouse.

Expected:
The click event to fire on the <button> and an alert to occur.  The alert does fire in the latest versions of Internet Explorer, Firefox, and Opera.

Actual:
The click event does not fire.

This only seems to happen when HTML content is injected.  If I set the innerHTML of the <button> to a plain string the issue does not occur.
Comment 1 Alexander Shalamov 2013-03-22 01:10:34 PDT
(In reply to comment #0)
> This only seems to happen when HTML content is injected.  If I set the innerHTML of the <button> to a plain string the issue does not occur.

The issue is not related to setting html / plain text content to a button. The problem is that mouse press and release events received by different elements of the button and click event is not sent. I have a patch that I'm testing at the moment. Will upload it when I'm sure that none of layout tests are failing with my modifications.
Comment 2 Lucas Forschler 2019-02-06 09:18:55 PST
Mass move bugs into the DOM component.