title | category |
---|---|
DOM Range |
JavaScript |
See http://devdocs.io/dom/document/createrange
var range = document.createRange()
See http://devdocs.io/dom/range
range
.setStart(startNode, startOffset)
.setEnd(endNode, endOffset)
.setStartBefore(node)
.setStartAfter(node)
.setEndBefore(node)
.setEndAfter(node)
.selectNode(node)
.selectNodeContents(node)
range
.collapse() // to end (a single point)
.collapse(true) // to start (a single point)
.collapsed // true | false
range
.cloneContents() // copy => DocumentFragment
.extractContents() // cut => DocumentFragment
.deleteContents() // delete
.insertNode(node)
range
.toString()
range
.collapsed // true/false
.startContainer // Node
.startOffset
.endContainer // Node
.endOffset
.commonAncestorContainer // closest of start and end containers