Set cursor at the end of the input

This commit is contained in:
Daoud Clarke 2021-12-16 21:55:04 +00:00
parent af29b4c039
commit 1d8b37add1
2 changed files with 4 additions and 1 deletions

View file

@ -11,7 +11,7 @@
Stoatally different.
<form action="/search">
<input type="search" id="search" name="s" />
<input type="search" id="search" name="s" value="" autofocus/>
</form>
<div id="results">

View file

@ -3,6 +3,9 @@
window.onload = (event) => {
const searchInput = document.getElementById('search');
const length = searchInput.value.length;
searchInput.setSelectionRange(length, length);
searchInput.addEventListener('keyup', (e) => {
console.log(searchInput.value);