4

I have following HTML and would like to disable the link using javascript.

<a style="white-space: nowrap;" onclick="return InstallWebApp(true);" id="uc_ii_lnkInstall" href="javascript:__doPostBack('uc_ii$lnkInstall','')">
<img style="border-width: 0pt; margin-right: 3px;" id="uc_ii_lnkInstallImg" alt="Install" title="Install" src="/CortexDotNet/pics/buttons/install_g.gif">
Install
</a>

The JavaScript I am using are :

 document.getElementById("uc_ii_lnkInstall").disabled = true;

However , it does not work , I could still click this this link after I have disabled the link using the above javascript.I look at the html , it does not seem to have the disable attribute in the a tag.Can anyone help me to explain this please?

mechanical_meat
170k25 gold badges237 silver badges231 bronze badges
asked Oct 14, 2010 at 2:18
0

4 Answers 4

9
document.getElementById("uc_ii_lnkInstall").onclick = function() { return false; };

The return value of false in the old-style event handler prevents the default action (i.e. loading the javascript: URL).

If you want to gray out the image link, you would also need to swap out the image's src URL with one pointing to a grayed-out version of the icon and change the text's color using .style.color = "gray";.

answered Oct 14, 2010 at 2:21
Sign up to request clarification or add additional context in comments.

Comments

1

I don't think the 'disable' attribute will work on links, it work mostly on form elements such as inputs, textarea, button, etc.

But as @idealmachine said normal links <a> can be disabled by returning false 'return false' in javascript/jquery.

answered Oct 21, 2010 at 11:52

Comments

0

For example:

let link_example = document.querySelector("#top-content .view-content a");
link_example.removeAttribute("href");
answered May 10, 2021 at 17:05

Comments

0

Here is a short and easy way to disable a link.

<a href="javascript:void(0)" >My link is disabled</a>
answered May 10, 2021 at 17:16

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.