Select text on contenteditable element

3/29/2020

A small helper function to select all text in a contenteditable element.

const selectElementContents = element => {
    const range = document.createRange()
    range.selectNodeContents(element)

    const selection = window.getSelection()
    selection.removeAllRanges()
    selection.addRange(range)
}