enable click event for anchor which was disabled using jquery
I am using the following code to disable the click event for anchor tags:
//disable Click event for links except navigation
$("a:not(#navigation a)").live('click', function(e) {
e.preventDefault;
return false;
});
I need to reenable or remove the implementation which was set as above 开发者_运维知识库on click of an another button.
How to do it in jquery?
To remove event handlers connected with live
, you can use die
:
$("a:not(#navigation a)").die('click');
To unbind a .live
event you could use .die
but I think a better approach would be the following:
$("#buttonToTriggerChange").click(function(e){
// Toggle between adding and removing the class "disable-links" from
// the <body> element
$(document.body).toggleClass('disable-links');
});
$("a:not(#navigation a)").live('click', function(e) {
// Only block the links if <body> has the class "disabled-links"
if($(document.body).hasClass('disabled-links')){
e.preventDefault();
return false;
}
});
You can kill this with die, according to the jquery docs. You should change your live event handling to a named function rather than an anonymous function:
function live_anchors(e){
e.preventDefault;
return false;
}
$("a:not(#navigation a)").live('click', live_anchors);
Then you should be able to undo that with:
$("a:not(#navigation a)").die('click', live_anchors);
精彩评论