A range represent a sequence of content at the character level within a node tree.
They are used in editing for
Below we will define the range that represents the olor sit ame
<p>Lorem ipsum dolor sit <em>amet, consectetur</em> adipiscing elit</p>
let p = document.querySelector("p");
let em = document.querySelector("em");
let range = new Range(),
pTextNode = p.childNodes[0],
emTextNode = em.firstChild;
range.setStart(pTextNode, 13); // from the 13 characters of the p element
range.setEnd(emTextNode, 3); // until the third character of em
var sel = window.getSelection();
sel.removeAllRanges();
sel.addRange(range);
A range has two associated boundary points
A boundary point consists:
A collapsed Range is empty and specifies only a single-point in the DOM tree.