Skip to content

Latest commit

 

History

History
67 lines (52 loc) · 1.02 KB

dom-range.md

File metadata and controls

67 lines (52 loc) · 1.02 KB
title category
DOM Range
JavaScript

Creating ranges

See http://devdocs.io/dom/document/createrange

var range = document.createRange()

Methods

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)

Collapsing

range
  .collapse()     // to end (a single point)
  .collapse(true) // to start (a single point)
  .collapsed      // true | false

Operations

range
  .cloneContents()   // copy => DocumentFragment
  .extractContents() // cut  => DocumentFragment
  .deleteContents()  // delete

  .insertNode(node)

Etc

range
  .toString()

Read-only attributes

range
  .collapsed         // true/false
  .startContainer    // Node
  .startOffset
  .endContainer      // Node
  .endOffset
  .commonAncestorContainer // closest of start and end containers