title: How to get x,y coordinates of text in paragraph (like Quora does)
body: <p>I want to be able to get the x,y coordinates of the end of a text string that has been highlighted in a web browser. I tried searching online for something similar and found that Quora does almost exactly what I want. Their code is obsfucated/ compressed though so I can't work out what they did.</p>
  
  <p>To see any example visit a question on Quora (such as this: <a href="http://www.quora.com/Job-Interviews/Whats-the-craziest-thing-you-ever-said-at-an-interview-and-still-got-the-job" rel="nofollow">http://www.quora.com/Job-Interviews/Whats-the-craziest-thing-you-ever-said-at-an-interview-and-still-got-the-job</a>) and highlight some text in an answer. A little box will pop-up that says 'Embed Quote'. Getting the position of the embedded quote is what I want to do.</p>
  
  <p>I've made a little demo that grabs the mouse position - but I'd like it to be more accurate if possible. There's a jsfiddle of the code here: <a href="http://jsfiddle.net/BinaryMoon/zy8hY/" rel="nofollow">http://jsfiddle.net/BinaryMoon/zy8hY/</a></p>
  
  <pre><code>$(function(){
      $(document.body).bind('mouseup', function(e){        
          var selection;
          if (window.getSelection) {
              selection = window.getSelection();
          } else if (document.selection) {
              selection = document.selection.createRange();
          }
  
          if ( selection.toString().length &gt; 3 ) {
              var tip = $('&lt;div class="pointer" /&gt;');
              var p = 
              tip.css({
                  'position':'absolute',
                  'left': e.pageX,
                  'top': e.pageY
              });
              tip.appendTo('.post'); 
          }
      });
  
      $(document.body).bind('mousedown', function(e){
          $('.pointer').remove();
      });
  });
  </code></pre>