title: Javascript: use window.getSelection() with single click?
body: <p>In JavaScript, I don't know how to use <code>window.getSelection()</code> with a single click?</p>
  
  <pre><code>var s = window.getSelection();
  s = s.toString().trim();
  alert(s);
  </code></pre>
  
  <p>HTML contains:</p>
  
  <pre><code>&lt;p&gt;This text contains --this; and that-that.&lt;/p&gt;
  </code></pre>
  
  <p>If single click on <em>--this;</em> the expected output should be <em>this</em>. 
  Double click should do this well, but how to do this with just a single click?</p>
  
  <p><strong>Thank you very much to all, I come to this solution:</strong></p>
  
  <pre><code>$('p').bind('click', function () {
      var sel_obj = window.getSelection(); //it will return an object
      sel_obj.modify("move","forward","character");
      sel_obj.modify("extend","backward","word");
  
      sel_obj.modify("move","backward","character");
      sel_obj.modify("extend","forward","word");
  
      var text = sel_obj.toString().trim();
      text = text.toLowerCase();
      alert (text);
  </code></pre>
  
  <p>References:
  <a href="https://developer.mozilla.org/en-US/docs/Web/API/Selection" rel="nofollow noreferrer">https://developer.mozilla.org/en-US/docs/Web/API/Selection</a></p>
  
  <p><a href="https://developer.mozilla.org/en-US/docs/Web/API/Selection/modify" rel="nofollow noreferrer">https://developer.mozilla.org/en-US/docs/Web/API/Selection/modify</a></p>
  
  <p><a href="https://stackoverflow.com/questions/7563169/detect-which-word-has-been-clicked-on-within-a-text">Detect which word has been clicked on within a text</a></p>