/html-dom /Basic
GitHub 4932★

Select the text content of an element

The following function selects the text content of the ele element:

const selectText = function (ele) {
const selection = window.getSelection();
const range = document.createRange();
range.selectNodeContents(ele);
selection.removeAllRanges();
selection.addRange(range);
};

See also

Follow me on and to get more useful contents.