<html>
<head>
<base href="https://bugs.webkit.org/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - Replacing input element using outerHTML with new element containing "autofocus" focuses newly replaced element"
href="https://bugs.webkit.org/show_bug.cgi?id=148177">148177</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Replacing input element using outerHTML with new element containing "autofocus" focuses newly replaced element
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr>
<tr>
<th>Product</th>
<td>WebKit
</td>
</tr>
<tr>
<th>Version</th>
<td>WebKit Nightly Build
</td>
</tr>
<tr>
<th>Hardware</th>
<td>Unspecified
</td>
</tr>
<tr>
<th>OS</th>
<td>Unspecified
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>Normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P2
</td>
</tr>
<tr>
<th>Component</th>
<td>HTML DOM
</td>
</tr>
<tr>
<th>Assignee</th>
<td>webkit-unassigned@lists.webkit.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>martijn.dashorst@gmail.com
</td>
</tr></table>
<p>
<div>
<pre>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.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are the assignee for the bug.</li>
</ul>
</body>
</html>