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

javascript - removeAttr("href") on anchor also removed text color - Stack Overflow

programmeradmin0浏览0评论

I have a web site that uses JQuery and JQuery UI.

For some links, I didn't want to use JQuery UI Theme's colors, so I overrided using my own css.

It all worked until I used $("#a_about").removeAttr("href") to remove the href from the anchors (so that the link wouldn't actually work, I just want to grab the click action) to my surprise, it also removed the color which my css applied, and returned to the color which JQuery UI Theme applied previously.

I tried to change the element on which the color is applied (the anchor itself, the parent container, etc...) but nothing helped. Thanks...

I have a web site that uses JQuery and JQuery UI.

For some links, I didn't want to use JQuery UI Theme's colors, so I overrided using my own css.

It all worked until I used $("#a_about").removeAttr("href") to remove the href from the anchors (so that the link wouldn't actually work, I just want to grab the click action) to my surprise, it also removed the color which my css applied, and returned to the color which JQuery UI Theme applied previously.

I tried to change the element on which the color is applied (the anchor itself, the parent container, etc...) but nothing helped. Thanks...

Share Improve this question edited Apr 4, 2011 at 9:02 BoltClock 725k165 gold badges1.4k silver badges1.4k bronze badges asked Apr 4, 2011 at 8:59 Nir O.Nir O. 1,6611 gold badge19 silver badges30 bronze badges 1
  • can you post some html code please? – jackJoe Commented Apr 4, 2011 at 9:01
Add a ment  | 

4 Answers 4

Reset to default 3

Instead of:

$("#a_about").removeAttr("href")

Use:

$("#a_about").attr("href","javascript:;")

Anchor without href is not really a link. As others said set it to something like # and to "cancel" the click, also have:

$("#a_about").attr("href", "#").click(function() { return false; });

It's because on some browser, a anchor a without attribute href is treat as normal text. So try change the href to javascript:; instead of remove it.

Don't touch the href. Prevent the default action in the event handler instead.

This way the link will continue to work if people, for example, middle click on it.

发布评论

评论列表(0)

  1. 暂无评论