Search code examples
javascriptjqueryeventspreventdefault

can e.preventDefault() be reversed?


i am looking for a way to .preventDefault() to make a transition and then allow the default behavior

$('.withTrans').click(function(e){
    e.preventDeault();
    $(this).animate('opacity','0',300,function(){
           e.resumeDefault();      // does something like this exist?
    });

})

Solution

  • $('.withTrans').click(function(event) {
        if ( $(this).data("prevented") === true ) {
            $(this).data("prevented", false);
            return;
        }
        event.preventDefault();
        $(this).animate('opacity', '0', 300, function() {
               $(this).data("prevented", true).trigger("click");
        });
    });