Reputation: 6125
Okay, so I am trying to figure out how to get a link href if the user has highlightened text is contained within a text...
So for example if the following is a link
<a href="http://www.google.com">Find us on Google</a>
and the user hightlights the text "Google"
<a href="http://www.google.com">Find us on Google</a>
So the question is: After the user highlights text (as in to copy and paste it) they well hit a button and it will return what the link is for the selected text.
I hope I made this clear, wasn't really sure how to phrase it.
Upvotes: 1
Views: 957
Reputation: 318182
window.getSelection().anchorNode.parentNode.href;
or in IE:
document.selection.createRange().parentElement().href;
should get the element's href where the text is selected ?
Upvotes: 7