Resolved: jQuery callback after function is complete

In this post, we will see how to resolve jQuery callback after function is complete

Question:

I have a script that has a lot of height animations. So i figured I could juste make one function with the animation and call it whenever I want. The thing is, when the function is complete I have various things that can be done.
So this is the solution I have so far that works well but that isn’t satisfying (hard to know which condition applies in which case):
But I would rather do the conditions just after the call instead like:
I looked in Stack overflow and found dozens of answers but, for the life of me, all failed in my case.
Here are, from the top of my head, some attempts I tried (and some were even found in Stack Overflow) but didn’t work in my case:
Most answers I found are variants with a function calling a third function when the second is done, which isn’t what I want. I want a function to be called and then get back a green light when it’s complete so that I can do something else directly. The answers dealing with my case are harder to find, for whatever reason.

Best Answer:

You can pass your code as a callback function, and call it from completion:

If you have better answer, please add a comment about this, thank you!

Source: Stackoverflow.com