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

7 Answers

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.

jquery preventdefault

jquery toggle calls preventDefault() by default, so the defaults don't work. you can't click a checkbox, you cant click a link etc etc

is it possible to restore the default handler?

function DoPrevent(e) {

// Bind:
$(element).on('click', DoPrevent);

// UnBind:
$(element).off('click', DoPrevent);

You can restore the default action (if it is a HREF follow) by doing this:

window.location = $(this).attr('href');


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


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

Use a boolean:

let prevent_touch = true;
document.documentElement.addEventListener('touchmove', touchMove, false);
function touchMove(event) { 
    if (prevent_touch) event.preventDefault(); 

I use this in a Progressive Web App to prevent scrolling/zooming on some 'pages' while allowing on others.