最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Disable Anchor tag and remove underline also in javascript - Stack Overflow

programmeradmin5浏览0评论

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 can I achieve this inside this function?

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 can I achieve this inside this function?

Share Improve this question edited Jun 11, 2012 at 5:57 munity wiki
5 revs, 3 users 69%
vaibhav bindroo 0
Add a ment  | 

4 Answers 4

Reset to default 3
obj.style.textDecoration = "none"

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

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;
}

Use this on HTML:

<a href="mylink" style="text-decoration
发布评论

评论列表(0)

  1. 暂无评论