I have a .click() event on an element. After it’s closed, this mob has a transition that happens and an AJAX call that goes through. That’s all that happens.
What I need is a callback to put inside the .click() function to execute when both of those things are done, even if transitions aren’t supported. Here’s a timeline:
jQuery needs to wait for the ajax call and the transition, then execute the callback after the ajax call has completed AND the transition has either finished or not happened at all.
How can I do this? Thanks!
NOTE: I’m using $.ajax() for the ajax call and a normal CSS3 transition on the element in question. I can detect transitionEnd with javascript event binding, I have a variable setup for that called transitionEnd and another variable that detects if the browser support transitions call supportsTrans.
Have a flag for each event, initially false. Hook the two events in question (
transitionEndand the ajaxsuccess, it sounds like). Each event sets its flag and calls a function. That function checks the flags: If both are set, it does something.Here’s an example using
animaterather than a CSS transition, just to keep things simple: Live example | sourceNote the error handling, in case the ajax call fails.