Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabled the a tag (link) by using javascript

Tags:

javascript

Does anyone how can I disabled the a tag (link) by using javascript?

Example:

<div class="sub-heading">
  Contact Details &nbsp; &nbsp; &nbsp; 
  <a href="./cust_add_edit_customer.php?action=edit_customer_details&amp;cust_code=12761">  
    <img class="imgVA editIconPad" src="../images/edit0.gif" 
      alt="Edit Contact Details" border="0" width="20" height="17">
  </a>
</div>

I hope to disabled this a tag after a button been clicked.

like image 653
Jin Yong Avatar asked Dec 08 '22 05:12

Jin Yong


2 Answers

I think the most user-friendly approach is to hide the link. In your button click handler do:

document.getElementById('anchorID').style.visibility = 'hidden';

Then to reenable it:

document.getElementById('anchorID').style.visibility = 'visible';
like image 181
Annabelle Avatar answered Dec 17 '22 06:12

Annabelle


Use an onclick="this.onclick=function(){return false}" attribute on the a tag. If there's a lot of buttons, you should iterate through them in a JavaScript script that adds an event listener for click that is a function that returns false.

like image 45
Eli Grey Avatar answered Dec 17 '22 07:12

Eli Grey