title: How to get selected text with JavaScript
body: <p>I'm a little confused why doesn't this code work!</p>
  
  <p>The HTML Markup:</p>
  
  <pre><code>&lt;div id="diva"&gt;&lt;b&gt;Score&lt;/b&gt; some &lt;i&gt;goals&lt;/i&gt;&lt;/div&gt;
  &lt;div id="soda"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>The JavaScript code:</p>
  
  <pre><code>function GetSelectedText () {
  if (window.getSelection) {  // all browsers, except IE before version 9
      var range = window.getSelection ();
      alert (range.toString ());
  } 
  else {
      if (document.selection.createRange) { // Internet Explorer
          var range = document.selection.createRange ();
          alert (range.text);
      }
  }
  }
  
  var butn = document.getElementById("soda");
  butn.onclick = function(){
      GetSelectedText();
  }
  </code></pre>