let ranges = [];
const sel = window.getSelection();
for (let i = 0; i < sel.rangeCount; i++) {
ranges[i] = sel.getRangeAt(i);
}
/* Each item in the ranges array is now
* a range object representing one of the
* ranges in the current selection */Selection: getRangeAt() method / notebook
Selection: getRangeAt() method
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.