What is the proper way in jQuery to remove an element from the DOM before its Promise is resolved?

What is the proper way in jQuery to remove an element from the DOM before its Promise is resolved?

Add Comment



  • 1 Answer(s)

    A returned Promise in jQuery 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 Promisesfrom resolving.

    Therefore, 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.

    Platinum Answered on 07/05/2018.
    Add Comment



  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.