I would like to know how I can rebind the previous behavior of a normal link!
example:
function removeDefaultBehaviour(objects){
objects.each(function(){
$(this).data('onclick',$(this).attr('onclick'));
$(this).attr('onclick','return false;');
});
};
function addDefaultBehaviour(objects){
objects.each(function(){
if($(this).data('onclick')!='')
$(this).attr('onclick',$(this).data('onclick'));
});
};
I tried to store the previous behavior in the data object of each link. But this didn’t work!
Any suggestions, how to restore the previous and default behavior of a link!
Thx
Markus
Don’t try to handle
onclickand other event handlers as strings, as DOMsetAttributeor jQueryattrwould do. Functions cannot be adequately serialised to a string. Instead use the normal DOM event handler properties such aselement.onclickto get and set the real function objects:However, juggling event handlers like this is a bit of a smell and usually suggests you’d be better off using bind: