Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 804237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:53:09+00:00 2026-05-14T23:53:09+00:00

I have the following lines of jQuery: // When dragging ends stop: function(event, ui)

  • 0

I have the following lines of jQuery:

// When dragging ends
stop: function(event, ui) {
    // Replace the placeholder with the original
    $placeholder.after( $this.show() ).remove();
    // Run a custom stop function specitifed in the settings
    settings.stop.apply(this);
},

I don’t want settings.stop.apply(this); to run UNTIL the line above is ($placeholder.after( $this.show() ).remove();), right now what’s happening is the settings.stop is running to early.

With jQuery, how can I sequence these two lines to not proceed until the first is complete?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T23:53:10+00:00Added an answer on May 14, 2026 at 11:53 pm

    Animations happen asynchronously, which is why your $this.show() doesn’t complete before the settings.stop.apply... line. All animations end up in the default (“fx”) queue, which get played out one after the other. You can add something (even though its not an animation) to this sequence by using the queue function. So to adapt your example:

    // When dragging ends
    stop: function(event, ui) {
        // Replace the placeholder with the original
        $placeholder.after( $this.show() ).remove();
        // Run a custom stop function specitifed in the settings
        var x = this;   //make sure we're talking about the right "this"
        $this.queue(function() {
            settings.stop.apply(x);
            $(this).dequeue();    //ensure anything else in the queue keeps working
        });
    },
    

    Edit in response to your comment “What do you mean by the right “this”?“:

    In JavaScript, this can be a tricky beast, that changes depending on the scope that it’s referenced from. In the callback passed to the queue function, this will refer to the DOM object that the queue is being executed on (i.e. the DOM object referred to by $this. However, it’s entirely possible that the this in the outer stop function is referring to some other object…

    Now, chances are, in your example, the outer this referred to the DOM object that is represented by the $this jQuery object (i.e. you’ve probably got a var $this = $(this); somewhere above where this snippet was taken from). In which case the x is unnecessary, since the two thiss would’ve been the same. But since I didn’t know, I thought I should make sure. So, I created a closure* by creating a new variable, x, that referred to the “right” this (x is now caught in the closure, so we know for sure that it refers to the right thing inside the queue callback).

    * It’s a bit of a slog, but if you make can it through that last linked article, you’ll end up with a great understanding of how javascript hangs together.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.