Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I tried document.getElementById("link1").disabled = true; but its did't work...so please help..


What I have tried:

I tried document.getElementById("link1").disabled = true; but its did't work...so please help..
Posted
Updated 4-Jun-18 5:13am

Suppose your link were inside of a <div> wrapper. Now, when your onclick event is triggered you disable the <div>, which disables all of its content. Or you could even hide the div (and thus its content).

You code sample is a little sparse.


Per correction in comment: How to Disable Links | CSS-Tricks[^] address the question.
 
Share this answer
 
v2
Comments
MadMyche 4-Jun-18 11:06am    
"disabled" is not a valid attribute for a <div>
The reason "disabled" most likely did not work is that it is not a valid attribute for a <a> element. It only works on elements you would normally find within a form.
W3 Schools > disabled attribute[^]

What I would try would be to remove the href attribute from the link when clicked.
 
Share this answer
 
Comments
W Balboos, GHB 4-Jun-18 11:26am    
Somehow I remember doing this type of thing in the past - but obviously not with the div. If you check my revised answer, I gave a link to one of the various work-arounds. Now I'm wondering if this was something I did in .NET just transferred the idea without check. Glad you caught it. The idea of hiding the link (via div) would work but isn't really what's asked for.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900