title | category | layout | intro |
---|---|---|---|
DOM Range |
JavaScript |
2017/sheet |
Quick reference to the HTML [DOM createRange API](https://devdocs.io/dom/range).
|
{:.-three-column}
var range = document.createRange()
See: https://devdocs.io/dom/document/createrange
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
range.collapse() // to end (a single point)
range.collapse(true) // to start (a single point)
range.collapsed // true | false
range.cloneContents() // copy => DocumentFragment
range.extractContents() // cut => DocumentFragment
range.deleteContents() // delete
range.insertNode(node)
range.toString()
range.collapsed // => true/false
range.startContainer // => Node
range.startOffset
range.endContainer // => Node
range.endOffset
range.commonAncestorContainer // closest of start and end containers