How to select part of the text in HTML input text using JavaScript

1 Answer

0 votes
<input id="iid" value="text text text" />
<button id="bid">Select Text</button>
const input = document.getElementById("iid");
const btn = document.getElementById("bid");
 
btn.addEventListener("click", ()=>{
   input.focus(); 
   input.setSelectionRange(0, 5);
})
 
   
     
     
/*
run:
 
     
*/

 



answered Jun 26, 2021 by avibootz
...