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

  • Home
  • SEARCH
  • 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 8594505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:12:56+00:00 2026-06-12T00:12:56+00:00

I have implemented a drag & drop feature using JQuery UI – my current

  • 0

I have implemented a drag & drop feature using JQuery UI – my current code is provided below:

My JavaScript function receives JSON array from PHP and then uses a loop to create the draggable elements:

<script type="text/javascript">
    function init() {
        var items = <?php echo $result_j;?>; //items is an one dimensional array

        for ( var i=0; i<<?php echo $total_rows_j;?>; i++ ) {      
            $('<div>' + items[i] + '</div>').data( 'item_name', items[i] ).attr( 'class', 'snk_button' ).appendTo( '#drag' );
         }

With the ‘items’ array I have created several div elements (above code) which I then turn into draggable elements (code below).

         $(".snk_button").draggable( {
            containment: '#drag_section',//Div #drag_section contains the Div #drag 
            stack: '#drag div',
            cursor: 'move',
            revert: true
         } )

Below is my droppable code:

$( "#dropp" ).droppable(
   drop: handleDrop
});

function handleDrop( event, ui ) {
    ui.draggable.draggable( 'option', 'revert', false );
} // End function handleDrop

So far, everything is fine with the draggable items attaching themselves to the droppable div.

Now, I want to tweak this behavior a little:

  1. I want the draggable items to arrange themselves ‘automatically’ in the droppable div (called ‘#dropp’ in this example), starting from the top left (they will be floating left). Currently this is not happening even though the ‘#dropp’ div has the ‘float:left’ property set. So, what should I do to have the draggable items arrange themselves when dropped on ‘#dropp’?
  2. When I take out a draggable item out of the droppable div (‘#dropp’) I want it return to the div that originally contained the draggable items (‘#drag’ in this example).

Can you please help implement these 2 behaviors?

  • 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-12T00:12:57+00:00Added an answer on June 12, 2026 at 12:12 am

    After trying this on my own and some R&D for nearly 5-6hrs, I have been able to solve both my problems.
    For benefit of others who might be facing the same issues, below is the additional code that is required to implement the behaviors described above:

    $( "#dropp" ).droppable({
        accept: '#drag div',
        drop: function(event, ui)
        {
        $("div#dropp").append (ui.draggable); 
        $(ui.draggable).css ({ position:"relative", top:"0px", left:"0px" })
                   .addClass("moved");
        } // End function for handling drop on '#dropp'
    }); //End $( "#dropp" ).droppable
    

    This has been added new:

    $( "#drag" ).droppable({
    accept : ".moved",
    drop : function (event, ui)
    {
        $("div#drag").append (ui.draggable);
        $(ui.draggable).css ({ position:"relative", top:"0px", left:"0px" });
    
    } // End function for handling drop on '#drag'
    }); // End $( "#drag" ).droppable
    

    That’s all is required to implement the behaviors described above. Hope somebody finds the information useful 🙂

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

Sidebar

Related Questions

I'm new to jquery I have implemented drag and drop operation using Kinetic.js I
i am using the code i have already implemented the table drag and drop
I have implemented my custom drag&drop by deriving from COleDataSource and COleDropTarget. Everythings work
I'm new to jQuery. I have implemented a drag and drop scenario. My question
I have implemented the JQuery Drag and Drop plug in into my web site.
I have implemented drag and drop in my application, but am having some difficulty
I have simple drag and drop functions implemented in QmainWindow the reference taken from
I'm trying to implement jQuery-File-Upload - I have it working when I drag &
I have implemented drag drop functionality to a surfacelistbox as explained here (http://msdn.microsoft.com/en-us/library/ff727837.aspx). It's
I have an app with 2 DataGridView's and have implemented Drag/Drop to allow the

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.