Move Selection to next word using JavaScript
<p>I have some html text i.e. </p>

<pre><code>This is line1
</code></pre>

<p>I can get the initial user selection using <code>window.getSelection()</code> assume it is 'This'. On a click of a button, I like the user selection to move to the next word i.e. 'is'. How can I do this? I currently have the following code which does not work:</p>

<pre><code>function myFunction()
{
var selection=window.getSelection();
selection.collapse(selection.focusNode, 0);
selection.modify("move","forward","word");
selection.extend(selection.focusNode, selection.focusOffSet);
}
</code></pre>

<p>and this is't good for me, because even the earlier word stays selected</p>

<pre><code>var selection = window.getSelection();
selection.modify("extend", "forward", "word");
</code></pre>
