Learn all about the jQuery function .promise().
.promise() method returns a dynamically generated Promise that is resolved once all actions of a certain type bound to the collection, queued or not, have ended.
"fx", which means the returned Promise is resolved when all animations of the selected elements have completed.
Resolve context and sole argument is the collection onto which
.promise() has been called.
target is provided,
.promise() will attach the methods onto it and then return this object rather than create a new one. This can be useful to attach the Promise behavior to an object that already exists.
Note: The returned Promise is linked to a Deferred object stored on the
.data() for an element. Since the
.remove() method removes the element’s data as well as the element itself, it will prevent any of the element’s unresolved Promises from resolving. If it is necessary to remove an element from the DOM before its Promise is resolved, use
.detach() instead and follow with
.removeData() after resolution.