const range = document.createRange();
range.setStart(startNode, startOffset);
range.setEnd(endNode, endOffset);Document: createRange() method / notebook
Document: createRange() method
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.