I have the following link element on a web page.How would I disable this using jQuery? It seems setting the disabled attribute does not disable it.
<A style="COLOR: black" href="javascript:__doPostBack('GridViewWithLinkqToSQL','Page$20')">20</A>
EDIT 1: ANSWER (with a fully functional sample page code)
Finally, I was able to enable/disable links. To enable simply attach a click handler in which default action of event is disabled, and for enabling remove the same click handler. In my code below, Link1 will open yahoo home page, while Link2 will show a javascript error, when both these links are enabled.
Html page code with necessary javascript/jQuery is as below. Using this approach you can enable/disable multiple hyperlinks within a div ( as in a Grid control). Here's a link to a video that will show a situation in which disabling and enabling links can be very useful: Disable all hyperlinks within a GridView during AJAX Postback. You will notice in the video that when user clicks on column header links or page number links, it doesn't do anything, which is what we want when a long AJAX postback happens and user starts to impatiently click on links.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Enable/Disable Links</title>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
</head>
<body>
<div id="div1">
<a href="https://www.yahoo.com">Link1</a>
<a style="COLOR: black" href="javascript:__doPostBack('GridViewWithLinkqToSQL','Page$20')">Link2</a>
</div>
<input id="Button1" type="button" value="Disable Links" onclick="ToggleLinks(true);" />
<input id="Button2" type="button" value="Enable Links" onclick="ToggleLinks(false);" />
<script type="text/javascript">
function ToggleLinks(disabled) {
var div1 = $('#div1');
// div1.find("*").prop("disabled", disabled);
if (disabled) {
div1.find("a").each(function (i, element) {
$(this).click(function (e) {
e.preventDefault();
return false;
});
});
}
else {
div1.find("a").each(function (i, e) {
$(this).unbind("click");
});
}
}
</script>
</body>
</html>