Archive

Archive for the ‘javascript’ Category

Enable or Disable an anchor tag in javascript: IE and Firefox compatible

September 29, 2010 Leave a comment

Hi,

To add full ‘disable’ functionality to both IE & Firefox browsers

Add or remove the href attribute (both browsers will enable/disable the anchor with this method).

To allow this to work you need to store the existing href value – I just add another (non standard html) attribute eg href_User_defined.

function disableAnchor(anchorObj, disable){
if(disable){
var href = anchorObj.getAttribute(“href”);
if(href && href != “” && href != null){
anchorObj.setAttribute(‘href_User_defined’, href);
}
anchorObj.removeAttribute(‘href’);
anchorObj.style.color=”gray”;
}
else{
anchorObj.setAttribute(‘href’, anchorObj.attributes[‘href_User_defined’].nodeValue);
anchorObj.style.color=”blue”;
}
}

Thanx

Ref Document:  http://geekswithblogs.net/TimH/archive/2006/01/19/66396.aspx

Advertisements
Categories: javascript, tricks