Please note that I will do this on the server side. However, since your tags are jquery related, I am posting a solution that you can try using jquery.
using jquery you can:
var link = $('#id_of_your_a_element'); $.ajax( url: link.attr('href'), error: function() { link.hide(); } );
EDIT
As noted in this example, this example hides the link. If you want to disable it, you can prevent the default behavior when the user clicks on the link:
link.click(function(e) { e.preventDefault(); });
or just remove the href attribute:
link.removeAttr('href');
source share