开发者

jQuery: Allow text selection inside <a>

开发者 https://www.devze.com 2023-04-02 16:03 出处:网络
When trying 开发者_开发问答to select text inside a, it\'s just dragging link. Is it possible to disable this behavior while keeping link clickable?

When trying 开发者_开发问答to select text inside a, it's just dragging link.

Is it possible to disable this behavior while keeping link clickable?

Thanks ;)


Make a fake link with CSS on a span and bind your events.

Use :hover CSS selector

I made it for you with this JSFiddle Demo


I think inside an <a> it is not possible, because the dragging is the behaviour of a lot of browsers to allow drag and drop of links betweens applications. You could work around this using JavaScript and by using another HTML element as a link, but that is miss-use in my opinion.


Use the cursor: text rule.

a {
   cursor: text;
}


If possible in your case, I would instead make it a label with onclick handler defined.

Instead of

<a href="google.com">MY LINK</a>

use

<label href="google.com" onclick="navigate()">MY LINK</label>

function navigate() {
    window.location = $(this).attr('href');
}

with proper style.

fiddle: http://jsfiddle.net/vcBRA/1/

0

精彩评论

暂无评论...
验证码 换一张
取 消