How to enable or disable an anchor using jQuery?
相关问题
- Views base64 encoded blob in HTML with PHP
- How to fix IE ClearType + jQuery opacity problem i
- jQuery add and remove delay
- Is there a way to play audio on a mobile browser w
- HTML form is not sending $_POST values
So with a combination of the responses above, I came up with this.
For situations where you must put text or html content within an anchor tag, but you simply don't want any action to be taken at all when that element is clicked (like when you want a paginator link to be in the disabled state because it's the current page), simply cut out the href. ;)
The answer by @michael-meadows tipped me off to this, but his was still addressing scenarios where you still have to / are working with jQuery/JS. In this case, if you have control over writing the html itself, simply x-ing the href tag is all you need to do, so the solution is a pure HTML one!
Other solutions without jQuery finagling which keep the href require you to put a # in the href, but that causes the page to bounce to the top, and you just want it to be plain old disabled. Or leaving it empty, but depending on browser, that still does stuff like jump to the top, and, it is invalid HTML according to the IDEs. But apparently an
a
tag is totally valid HTML without an HREF.Lastly, you might say: Okay, why not just dump the a tag altogether than? Because often you can't, the
a
tag is used for styling purposes in the CSS framework or control you're using, like Bootstrap's paginator:http://twitter.github.io/bootstrap/components.html#pagination
If you are trying to block all interaction with the page you might want to look at the jQuery BlockUI Plugin