Inserting cursor after an inserted node
<p>So I have a method that takes a tag and wraps the selected text in that tag. </p>

<pre><code>function wrap(tag) 
{               
    var sel, range;
    if (window.getSelection)
    {
        sel = window.getSelection();
        if (sel.rangeCount)
        {
            range = sel.getRangeAt(0);
            var selectedText = range.toString();
            range.deleteContents();
            range.insertNode(document.createTextNode('['+tag+']'+selectedText+'[/'+tag+']'));                            
        }
    } 
}
</code></pre>

<p>This issue with this however, is after it's done wrapping the text and inserting the node the cursor (where they are typing) is placed BEFORE the inserted text. </p>

<p>Is there such way to insert the text and have the cursor remain at the end of it? </p>

<p>Please note i'd prefer if this could be done without the use of jQuery or any other library. I only need it to work in webkit (Safari).</p>
