Elliott
Elliott

Reputation: 5609

Disabling a button defined in an anchor tag

I am using a fairly standard technique to create a button on my page using an anchor tag.
Specifically:

<a href="#" id="downloadBtn" onclick="doSomething()"><span style="margin-left:17px;">Download</span></a>

Initially I want to disable this button. But because I implement it as an anchor tag, I don't know how to do this. As a regular Input button, I would just add the attribute disabled=true, but what do I do here?

Thank you for your help.

Elliott

Upvotes: 2

Views: 4177

Answers (2)

Dhaval Shukla
Dhaval Shukla

Reputation: 1127

InOrder to disable it just remove your href and add it later using javascript:

HTML:

<a id="downloadBtn" onclick="doSomething()"><span style="margin-left:17px;">Download</span></a>

JavaScript:

$("a").attr("href", "http://www.google.com/")  

Upvotes: 1

njbair
njbair

Reputation: 1982

Initially, set onclick="return false", then use your script to change the value of onclick when the time comes.

You could also add a class to the anchor, then use CSS to style the link so that it does not look like a link. Then remove that class from the element at the same time that you change the value of onclick.

Upvotes: 1

Related Questions