This LINK < href="page.htm" disabled>LINK</a> is supposed to be disabled
To disable the default action of the link you need to add return false to an onclick event within the link
This LINK < href="page.htm" disabled onclick="return false">LINK</a> is disabled
You can use a script to dynamically change the disabled status of the link.
|
Enable Link 1 Enable Link 2 |
Link 1 Link 2 Link 3 |
In my example above, when the page has loaded the script looks through all the links in the page for those that contain the class name "disabled", and disables those links, you can then toggle those links between the disabled and enabled state.
The link(s) are coded into the page as normal and includes the class "disabled". The "disabled" css rule makes sure the link displays the same, adding the strike through effect, in both browsers.
Here's a few more examples:
This Test Link 1 will be disabled when it has been clicked allowing the link only to be used once
This Test Link 2 is disabled, when this Keyword is been clicked the link will be enabled
The following example link will be enabled on mouseout
Move your mouse over the link and click away, when you're ready move your mouse off the link to enable it, then go back and click it.
How the link(s) are disabled/enabled is your preference but the basics are as follows:
Give the link an ID
To disable a link use
document.getElementById(id).onclick = function(){return false} // cancel default action of the link
To re-enable the link use
document.getElementById(id).onclick = function(){return true}
If the link is being used to run a function that function would normally be assigned to the onclick event but when you dynamically assign an onclick event to the link it over-rides any previous onclick event so to run the function you put it in the href as "javascript:functionName()"