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
4 Answers
Reset to default 3Instead 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.