Select text on contenteditable element

29/03/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)
}