How to remove a &quot;href&quot; from a tag <a>with JQuery/JavaScript?</a>


I have an <a> tag with a properly set hyperlink. However, I would like to remove it when firing an event. The same tag has a properly set ID, too (unique, valid, and the like).

I would like to know if there is a function to remove the href attribute and thus make the link invalid, or if there is a way to just disable this link.


The modern solution to disable a link is CSS only: ( for modern browsers )

$('#minhaID').css("pointer-events", "none");

// e para re-activar basta usar:
$('#minhaID').css("pointer-events", "");


You can also use like this:

$('#minhaID').attr("href", "");

Or yet:

$('#minhaID').removeAttr('href'); // note que esta opcção remove algumas caracteristicas importantes do elemento como focus.

depending on the use you want to give.

Note: Chrome has an open discussion about whether to no longer support pointer-events.

Scroll to Top