Disable link using javascript

I have the following HTML and you want 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>

I am using JavaScript:

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

However, this will not work, I could still click on this link after I disabled the link using the javascript above. I am looking at html, it does not have the disable attribute in the tag. help me explain this please?

+3
source share
2 answers
document.getElementById("uc_ii_lnkInstall").onclick = function() { return false; };

A false value in the old-style event handler prevents the default action (i.e., loads javascript: URL).

, URL- src, .style.color = "gray";.

+9

, "disable" , , , , ..

@idealmachine , <a> , false 'return false' javascript/jquery.

+1

Source: https://habr.com/ru/post/1769468/


All Articles