How to unbind a listener that is calling event.preventDefault() (using jQuery)? How to unbind a listener that is calling event.preventDefault() (using jQuery)? jquery jquery

How to unbind a listener that is calling event.preventDefault() (using jQuery)?


In my case:

$('#some_link').click(function(event){    event.preventDefault();});

$('#some_link').unbind('click'); worked as the only method to restore the default action.

As seen over here: https://stackoverflow.com/a/1673570/211514


Its fairly simple

Lets suppose you do something like

document.ontouchmove = function(e){ e.preventDefault(); }

now to revert it to the original situation, do the below...

document.ontouchmove = function(e){ return true; }

From this website.


It is not possible to restore a preventDefault() but what you can do is trick it :)

<div id="t1">Toggle</div><script type="javascript">$('#t1').click(function (e){   if($(this).hasClass('prevented')){       e.preventDefault();       $(this).removeClass('prevented');   }else{       $(this).addClass('prevented');   }});</script>

If you want to go a step further you can even use the trigger button to trigger an event.