<a id="a$id" onclick="check($id,1)" href="javascript:void(0)" class="black">Qualify</a>
After "href" is removed, is "Qualify" still clickable?
Answer: Use the jQuery removeAttr() method You can easily remove the clickable behavior from a link through removing the href attribute from the anchor element ( <a> ) using the jQuery removeAttr() method.
We can remove the href by: Setting an empty href – ELEMENT. href = "" Or removing it entirely – ELEMENT.
In order to disable an HTML Anchor Link (HyperLink), the value of its HREF attribute is copied to the REL attribute and the value of HREF attribute is set to an empty JavaScript function. This makes HTML Anchor Link (HyperLink) disabled i.e. non-clickable.
Your title question and your example are completely different. I'll start by answering the title question:
$("a").removeAttr("href");
And as far as not requiring an href, the generally accepted way of doing this is:
<a href"#" onclick="doWork(); return false;">link</a>
The return false is necessary so that the href doesn't actually go anywhere.
If you want your anchor to still appear to be clickable:
$("a").removeAttr("href").css("cursor","pointer");
And if you wanted to remove the href from only anchors with certain attributes (eg ones that just have a hash mark as the href - this can be useful in asp.net)
$("a[href='#']").removeAttr("href").css("cursor","pointer");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With