I previously asked why setSelectionRange was't working and the answer was because it only works with input fields. But I would like to try to develop a spreadsheet type page using the contenteditable attribute.
window.onkeydown = function(e) {
if (e.keyCode === 113) {
setFocus()
}
}
function setFocus() {
element = document.getElementById('test')
element.focus() // works
.setSelectionRange(3,3) // Doesn't work
}
<div id="test" contenteditable>testing</div>
<p>Click in the Result window and then press F2.</p>
How can I place the cursor at the end of the field once the user presses F2?