Select specific word with Javascript?
<p>I have the following code which selects the entire contents of an element:</p>

<pre><code>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);
}
</code></pre>

<p>Which I call through:</p>

<pre><code>selectElement(document.getElementById("input"));
</code></pre>

<p>If <code>#input</code> looks like this:</p>

<pre><code>&lt;div id="input"&gt;
Lorem Ipsum Dolor Sit
&lt;/div&gt;
</code></pre>

<p>How can I select characters <code>0-7</code>, so that the selection would be:</p>

<pre><code>&lt;div id="input"&gt;
[Lorem I]psum Dolor Sit
&lt;/div&gt;
</code></pre>

<p>I figured setting the <code>setStart</code> and <code>setEnd</code> would work, but I can only set it from <code>0-1</code>.</p>

<p>Can I select the text inside the node, instead of the node itself?</p>
