chan.dev / posts

Select DOM contents programatically

🌱 This post is in the growth phase. It may still be useful as it grows up.

function selectContents(domNode) {
let range = document.createRange()
let sel = window.getSelection()
range.selectNodeContents(domNode)
sel.removeAllRanges()
sel.addRange(range)
}