title: Return HTML from a user-selected text
body: <p>I have the following, very simple html page:</p>
  <pre><code>&lt;html&gt;
      &lt;head&gt;
      &lt;script type=&quot;text/javascript&quot;&gt;
          function alertSelection()
          {
              var selection = window.getSelection();
              var txt = selection.toString();
              alert(txt);
          }
      &lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
          This is &lt;span style=&quot;background-color:black;color:white&quot;&gt;the&lt;/span&gt; text.
          &lt;div style=&quot;background-color:green;width:30px;height:30px;margin:30px&quot;
              onmouseover=&quot;alertSelection()&quot;&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>When I select the entire first line and mouseover the square, I get an alert with &quot;This is the text.&quot;.</p>
  <p>How would I fix this so the span tag or any other selected HTML isn't stripped out of the alert message?</p>
  <p><strong>edit:</strong> I'm looking specifically for how to get the full HTML from <code>window.getSelection()</code>.  The alert dialog was just how I was attempting to validate the code.  I'm only concerned about this working in Safari.</p>