Posts Tagged ‘disable a tag’

I have searched many sites for to disable anchor and I know that IE supports ‘disable’ property for anchor tag, however Firefox does not support this. So whenever you try with ‘disable’ property of an anchor tag “<a></a>” you will get proper output in IE browser but not in Firefox browsers.

I have found a very good article which disables the anchor tag using few tricks because without tricks it is not possible to mange disable anchor in Firefox. You can find this article here. However, you can copy the same javascript script of above article as below.
function disableAnchor(obj, disable){
var href = obj.getAttribute("href");
if(href && href != "" && href != null){
obj.setAttribute('href_bak', href);
obj.setAttribute('href', obj.attributes['href_bak'].nodeValue);"blue";

Also note that you can perform the same thing on the code behind (for if you are using a server control for anchor tag and you want to disable the anchor, you just need to remove the ‘href’ property usingĀ  MyAnchor.Attributes.Remove("href") and then just apply gray color to anchor and its done. It will work in both IE and Firefox (javascript and server code both).

Happy Programming!!