Bug 148177 - Replacing input element using outerHTML with new element containing "autofocus" focuses newly replaced element
Summary: Replacing input element using outerHTML with new element containing "autofocu...
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-08-19 07:00 PDT by Martijn Dashorst
Modified: 2015-08-19 07:00 PDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martijn Dashorst 2015-08-19 07:00:50 PDT
When replacing an existing <input> element using outerHTML where the new markup has <input autofocus> puts the focus on the new element instead of keeping the focus on the current form element.

The markup below illustrates the issue:

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
    function replaceLastName() {
        var newMarkup = "<input type='text' id='lastname' autofocus placeholder='Last name' value='Banana'>";
        document.getElementById("lastname").outerHTML = newMarkup;
    }
</script>
</head>
<body>
    <form>
        <input type="text" id="lastname" autofocus placeholder="Last name">
        <input type="text" id="firstname" placeholder="First name" onfocus="replaceLastName();">
        <input type="submit">
    </form>
</body>
</html>

When you modify the contents of field 'lastname' and switch the focus to 'firstname', Safari 8 and Webkit nightly remove the focus from the 'firstname' field and put the focus on 'lastname'.

All other major browsers retain the focus on the 'firstname' field.