How can I make a link selectable, like normal text, without triggering the mouse click?
Unlinked text can be easily selected from the middle. I want to make the link selectable if the user holds down the mouse, but if it’s a single click then open the link as normal.
This behaviour is defined by the browser so there’s not much you can do about it. I believe some browsers do allow you to select anchor text from any point (Opera?), not just the start and end, but that’s not much use to you.
If you really want to change the default browser behaviour (which is rarely a good idea), then read on…
One potential solution could be to not use
aelements, but instead use something likespan. Give eachspanlink a common class and store the intended URL:Then use JavaScript (you’ve tagged the question with jQuery so I’ll use jQuery here) to redirect the user:
Obviously you would need to style
.linkSpanappropriately to make it appear more like an actual link.Update (following @Madmartigan’s comment) – if you hold the mouse button down when the cursor is not over the link, then move over the link itself, you can start selecting text from any point within the link. I managed that in Chrome at least.