Please Help how to enable or disable the anchor tag using jquery
$("a").click(function(){
alert('disabled');
return false;
});
To prevent an anchor from following the specified HREF, I would suggest using preventDefault()
:
$(document).ready(function() {
$('a.something').click(function(e) {
e.preventDefault();
});
});
See:
http://docs.jquery.com/Events/jQuery.Event#event.preventDefault.28.29
Also see this previous question on SO:
http://stackoverflow.com/questions/970388/jquery-disable-a-link/970413#970413
If you are trying to block all interaction with the page you might want to look at the jQuery BlockUI Plugin
You never really specified how you wanted them disabled, or what would cause the disabling.
First, you want to figure out how to set the value to disabled, for that you would use JQuery's Attribute Functions, and have that function happen on an event, like a click, or the loading of the document.
The app I'm currently working on does it with a CSS style in combination with javascript.
a.disabled { color:gray; }
Then whenever I want to disable a link I call
$('thelink').addClass('disabled');
Then, in the click handler for 'thelink' a tag I always run a check first thing
if ($('thelink').hasClass('disabled')) return;
i worked with all the samples given above, but still i am unable to disable the link tag
but i could hide the link with this code: $('a.add').hide();
similarly, please suggest some other way to disable the link tag
It's as simple as return false;
ex. jQuery("li a:eq(0)").click(function(){ return false; })
or
jQuery("#menu a").click(function(){ return false; })
I found an answer that I like much better here
Looks like this:
$(document).ready(function(){
$("a").click(function () {
$(this).fadeTo("fast", .5).removeAttr("href");
});
});
Enabling would involve setting the href attribute
$(document).ready(function(){
$("a").click(function () {
$(this).fadeIn("fast").attr("href", "http://whatever.com/wherever.html");
});
});
This gives you the appearance that the anchor element becomes normal text, and vice versa.