Make programmatic range selection visible to the user?
-
07-07-2019 - |
Question
How can I make a programmatical page selection visible to the user, as if it was selected by the user?
var range = document.createRange();
var startPar = [some node];
var endLi = [some other node];
range.setStart(startPar,13);
range.setEnd(endLi,17);
Thank you.
Solution
Use:
window.getSelection().addRange(range);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow