When I select a link (with no ids or classes) within a paragraph, I need to get the selected links href value. How do I do it in jQuery? I am using document.getSelection() method for that. But I don’t see any method in document.getSelection() which returns the href value.
When I select the link by dragging the mouse, I am able to get the href value like below.
currentLink = document.getSelection().anchorNode.parentElement.href;
But when I select the link by double clicking the text, the above command will not return the href value. Please help.
Here, I wrote you a little something to get you started. It’s more cross-browser than your original code:
And here’s a jsFiddle demo.