Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?
    });

})
like image 364
Toni Michel Caubet Avatar asked Mar 04 '12 15:03

Toni Michel Caubet


People also ask

What is e preventDefault () method?

The preventDefault() method stops the default action of a selected element from happening by a user. This method does not accept any parameter and works in two ways: It prevents a link from following the URL so that the browser can't go another page. It prevents a submit button from submitting a form.

What is opposite of event stopPropagation ()?

preventDefault = false; e. stopPropagatio = false; javascript.

What is the difference between event preventDefault () and return false?

The preventDefault stops the default browser behaviour when an event is fired like not redirecting the page on url click etc. The returnfalse also stops the default browser behaviour when an event is fired and does not let the event propagate. The callback execution is also stopped is returned immediately when called.

Why is the event preventDefault () command used?

The preventDefault() method is used to prevent the browser from executing the default action of the selected element. It can prevent the user from processing the request by clicking the link.


1 Answers

$('.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");
    });
});
like image 62
Andreas Louv Avatar answered Sep 23 '22 16:09

Andreas Louv