Reputation: 36421
When I clear input input.value = '';
the input field loses focus. Is there a way to clear it and keep focus on it so the user can keep typing?
Upvotes: 1
Views: 735
Reputation: 4783
input.focus();
var input = document.getElementById("txt");
function clicked(){
input.value = '';
input.focus();
}
<input type="text" id="txt" />
<button onclick="clicked()"> Clear </button>
Upvotes: 1