Reference
Creating ranges
var range = document.createRange()
See: https://devdocs.io/dom/document/createrange
Methods
range
.setStart(startNode, startOffset)
.setEnd(endNode, endOffset)
.setStartBefore(node)
.setStartAfter(node)
.setEndBefore(node)
.setEndAfter(node)
.selectNode(node)
.selectNodeContents(node)
See: https://devdocs.io/dom/range
Collapsing
range.collapse() // to end (a single point)
range.collapse(true) // to start (a single point)
range.collapsed // true | false
Operations
range.cloneContents() // copy => DocumentFragment
range.extractContents() // cut => DocumentFragment
range.deleteContents() // delete
range.insertNode(node)
String
range.toString()
Read-only attributes
range.collapsed // => true/false
range.startContainer // => Node
range.startOffset
range.endContainer // => Node
range.endOffset
range.commonAncestorContainer // closest of start and end containers