Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove "href" with Jquery?

Tags:

jquery

href

<a id="a$id" onclick="check($id,1)" href="javascript:void(0)"  class="black">Qualify</a> 

After "href" is removed, is "Qualify" still clickable?

like image 542
Steven Avatar asked Nov 06 '09 14:11

Steven


People also ask

How to remove href tag using jQuery?

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.

How do you remove a href?

We can remove the href by: Setting an empty href – ELEMENT. href = "" Or removing it entirely – ELEMENT.

How do you make an anchor link not clickable or disabled?

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.


2 Answers

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.

like image 106
Langdon Avatar answered Oct 07 '22 21:10

Langdon


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"); 
like image 23
Brad Parks Avatar answered Oct 07 '22 21:10

Brad Parks