Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you make an anchor link non-clickable or disabled?

Tags:

jquery

I have an anchor link that I want to disable once the user clicks on it. Or, remove the anchor tag from around the text, but definitely keep the text.

<a href='' id='ThisLink'>some text</a> 

I can do this easily with a button by adding .attr("disabled", "disabled");
I successfully added the disabled property, but the link was still clickable.
I don't really care if the text is underlined or not.

Any clue?

When you click on the wrong musician, it should just add "Wrong" and then become unclickable.
When you click and you are correct, it should add "Awesome" and then disable all <a> tags.

like image 875
Evik James Avatar asked Oct 04 '11 22:10

Evik James


People also ask

How do I make an anchor link not clickable?

In order to disable a HTML Anchor Link (HyperLink), the value of its HREF attribute is copied to the REL attribute and the value of HREF attribute is set to an empty JavaScript function. This makes the HTML Anchor Link (HyperLink) disabled i.e. non-clickable.


2 Answers

The cleanest method would be to add a class with pointer-events:none when you want to disable a click. It would function like a normal label.

.disableClick{     pointer-events: none; } 
like image 151
mvinayakam Avatar answered Sep 22 '22 06:09

mvinayakam


<a href='javascript:void(0);'>some text</a> 
like image 33
Shiv Kumar Sah Avatar answered Sep 21 '22 06:09

Shiv Kumar Sah