Select the contents of an element

suggest change
let sel = document.getSelection();

let myNode = document.getElementById('element-to-select');

let range = document.createRange();
range.selectNodeContents(myNode);

sel.addRange(range);

It may be necessary to first remove all the ranges of the previous selection, as most browsers don’t support multiple ranges.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Selection API:
*Select the contents of an element

Table Of Contents
16Map
17Set
70Selection API