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 8250937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:04:23+00:00 2026-06-08T00:04:23+00:00

I am just getting started with this, but I am wondering how could I

  • 0

I am just getting started with this, but I am wondering how could I take the very simple example below and modify so that if the draggable div is already placed on the droppable div it won’t fire the alert.

      <script type="text/javascript">
          $(function () {
              $("#draggable-1").draggable();
              $("#draggable-2").draggable();


              $("#droppable").droppable({
                  drop: function (event, ui) {
                      var currentId = $(ui.draggable).attr('id');

                      if (currentId == "draggable-1") {
                          $(this)

                          // would like to prevent this if draggable is already dropped!
                          alert("Adding Item #1.")


                      } else {
                          $(this)
                          alert("Adding Item #2.")
                      }
                  }
              });
          });
      </script>
    <table width="100%"><tr><th>Draggable</th><th>Order Section</th><tr><td>
    <div id="draggable-1">
        <p>Item #1</p>
    </div>

    <div id="draggable-2">
        <p>Item #2.</p>
    </div>

    <div id="droppable">
        <p>Add Your Item</p>  
    </div>
  • 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-06-08T00:04:24+00:00Added an answer on June 8, 2026 at 12:04 am

    One solution that worked for me:

    var wasInDrop = false;
    var finishInDrop = false;
    $("#draggable_1").draggable({
        start:  function(event, ui){
                if (! finishInDrop){
                    wasInDrop = false;
                }
                finishInDrop = false; //will be set to true if landing in drop.
            },
        stop:     function(event, ui){
                if (finishInDrop && !wasInDrop){
                              alert("Adding Item #1.");
                }
                if (finishInDrop){ wasInDrop=true;}
    
            }
        });
    
    $("#droppable").droppable({
        drop: function (event, ui) {
            $(this)
            var currentId = $(ui.draggable).attr('id');
            if (currentId == "draggable_1") {
                finishInDrop = true; //for this time.
            }
        });
    

    And so forth. The idea is that the draggable fires the alert, if:

    1. It finishes inside droppable.
    2. It didn’t start inside droppable.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry, if this is a noobish question, but I'm just getting started with Rails
I'm perhaps being a bit lazy asking this here, but I'm just getting started
I just started getting this error today, seemingly out of nowhere. Any one see
I'm just getting started on writing functions instead of writing everything inline. Is this
I am just getting started with NHaml and ran into a snag. This is
I'm just getting started with Threads in Java so this might be a basic
I'm just getting started with Doxygen, and have done considerable searching on this, so
I'm fairly proficient in mySQL and MSSQL, but I'm just getting started with postgres.
I am just getting started with HTML/JavaScript, and I have a simple question. I
I'm just getting started using Mustache and I have this rendering problem. I send

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.