title: Get clicked element in JQuery
body: <p>I'm using the following code to get the selected text, my question is, how can I get the element where the text was selected? I have 100 rows and 10 columns and I want to get the td and tr object and I want to check weather the text was selected inside the table.</p>
  
  <pre><code>function getSelectedText() {
    var t = '';
    if(window.getSelection){
      t = window.getSelection();
    }else if(document.getSelection){
      t = document.getSelection();
    }else if(document.selection){
      t = document.selection.createRange().text;
    }
    return t;
  }
  $(document).bind("mouseup", putSelectedToInput);
  
  function putSelectedToInput(){
    var st = getSelectedText();
  
    if(st!=''){
      $("#params_oldname").val($.trim(st));
    }
  }
  </code></pre>