views:

849

answers:

3

I have a anchor tag which I would like to disable or enable depending upon some condition. I am able to achive this using the following function

    function disableEnableAnchor(obj, disable) {
    if(disable)
    {
        var href = obj.getAttribute("href");
        if(href && href != "" && href != null)
            obj.setAttribute('href_bak', href);

        obj.removeAttribute('href');        
   }
   else {
    var href_bak = obj.attributes['href_bak'].nodeValue;        
    obj.setAttribute('href', href_bak);
    }
   }

But I am not able to remove the underline when the anchor is in a disabled state . How should I achieve this inside this function ? Help !

+3  A: 
obj.style.textDecoration = "none"
virsir
this wouldn't work as it would make the obj lose its already set text decoration like disabled and greying out.
vaibhav bindroo
+1  A: 

You might want to consider replacing the anchor with a span.

spender
What I want is that once the anchor is disabled i.e it doesnt contain 'href' attribute and attribute 'disabled' is true , the underline should not appear. how should I go about this ?
vaibhav bindroo
A: 

This sounds like a stylesheet issue. Is there something like

a {
    text-decoration: underline;
}

in a CSS file that’s applied to the page?

Replacing it with the following CSS should make <a> tags only be underlined when they have an href attribute.

a:link,
a:visited,
a:hover,
a:active {
    text-decoration: underline;
}
Paul D. Waite