1

There are many article about how to get the user selected text in HTML page. But my question is how to get the corresponding DOM element instead of only text? It might be similar as FireBug, the text node must be a leaf in the DOM tree, how can I get the element?

Thanks

cn1h
  • 1,188
  • 4
  • 16
  • 24
  • I would say that's almost impossible to do. What if the selection was through multiple tags, how would you discern the parent element? would it be the body? where does the node stop?...if you're jsut using textareas, i could see that bein feasible, but you'd still have to stop the bubbling at the textarea to get the element. [I don't have the time to write a fiddle, so here's a comprehensive link with examples you can fiddle yourself](http://help.dottoro.com/ljqmgspu.php) – Ohgodwhy Jun 26 '12 at 07:24
  • 2
    See this question: http://stackoverflow.com/questions/1335252/how-can-i-get-the-dom-element-which-contains-the-current-selection . Maybe this is what you are looking for – U.P Jun 26 '12 at 08:37

0 Answers0