I have this simple input with the text inside:
document.querySelector('.input').value = 'Double click on words without extra space'
.input {
width: 400px
}
<input type="text" class="input" placeholder="">
Except the last word in the input if you double-click any other words it will be selected with an extra space afterwards.
Is there any solution so that double-clicking any word in the input only select the whole word without that space?
2
Answers
You can modify the text selection using
Selection#modify()
with parametersalter: "extend"
,direction: "left"
andgranularity: "character"
.From developer.mozilla.org:
Probably a workaround using
setSelectionRange()
: