I have the following code that selects the entire contents of an element:
function selectElement(element) { var sel = window.getSelection(); sel.removeAllRanges(); var range = document.createRange(); range.setStart(element, 0); range.setEnd(element, 1); sel.addRange(range); console.log(range); }
What I call:
selectElement(document.getElementById("input"));
If #input looks like this:
<div id="input"> Lorem Ipsum Dolor Sit </div>
How to select characters 0-7 so that the selection is:
<div id="input"> [Lorem I]psum Dolor Sit </div>
I decided to install setStart and setEnd , but I can only install it from 0-1 .
Is it possible to select the text inside the node, and not the node itself?
source share