As a follow up to Select range in contenteditable div
Stackoverflow doesn't allow me comment to Tim's "answer", but I've just tried the Tims code into jsfiddle and I don't see it working on Chrome or Edge now, maybe it worked on an earlier browser
var mainDiv = document.getElementById("main");
var startNode = mainDiv.firstChild.firstChild;
var endNode = mainDiv.childNodes[2].firstChild;
var range = document.createRange();
range.setStart(startNode, 6); // 6 is the offset of "world" within "Hello world"
range.setEnd(endNode, 7); // 7 is the length of "this is"
var sel = window.getSelection();
sel.removeAllRanges();
sel.addRange(range);
https://jsfiddle.net/Abeeee/zc7kwar8/1/
Edge throws the console error "Invalid argument" pointing at the range.setStart command (line 6), and the Chrome console says "Uncaught TypeError: Failed to execute 'setStart' on 'Range': parameter 1 is not of type 'Node'" on the same range.setStart line.
Does anyone have an suggestion on how to make this work on a "modern" browser? (Chrome Version 62.0.3202.94 (Official Build) (64-bit))
Thanks Abe