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