title: Add element w/ text node after user selection
body: <p>I have the following function that creates a new text node at the end of a document when called, using the value of text within a text field:</p>
  
  <pre><code>   function addAfter () {
        var elem = document.getElementById('textfield').value;
        var h = document.createElement('span');
        var t = document.createTextNode(elem);    
        h.appendChild(t);
        document.body.appendChild(h);
     }
  </code></pre>
  
  <p>What I would like it to do would be to add the text immediately after user-selected text (like when you click and drag to select text). What needs to replace the <code>document.body.appendChild(h);</code> for this to work?</p>