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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:27:40+00:00 2026-05-27T14:27:40+00:00

I am using jQuery draggable/droppable to enable elements in a grid to be swapped.

  • 0

I am using jQuery draggable/droppable to enable elements in a grid to be swapped. For example, when element 1 is dropped onto element 2 they change places.

There are two problems:

  1. After a successful drag-drop the clone still floats
    back to its original position. How can I prevent this? I only want
    it to float back if it’s not dropped onto a valid target.

  2. Ideally I’d like to set helper: original as well, but when I tried
    this I couldn’t work out how to correctly calculate the swapped
    positions in the drop function.

I’ve put the code on jsFiddle, and below for reference:

<div id="room"></div>

<script>
$(function() {
//Set up seats - four rows of eight
for (var row = 0; row < 4; row++) {
    for (var col = 0; col < 8; col++) {
        $('#room').append('<div class="seat" style="top: ' + (row * 45 + 15) + 'px; left: ' + (col * 117 + 18) + 'px;">' + (row * 4 + col + 1) + '</div>');
    }
}

//Swap function from http://blog.pengoworks.com/index.cfm/2008/9/24/A-quick-and-dirty-swap-method-for-jQuery
jQuery.fn.swap = function(b) {
    b = jQuery(b)[0];
    var a = this[0];
    var t = a.parentNode.insertBefore(document.createTextNode(''), a);
    b.parentNode.insertBefore(a, b);
    t.parentNode.insertBefore(b, t);
    t.parentNode.removeChild(t);
    return this;
};

$(".seat").draggable({
    revert: true,
    helper: "clone"
});

$(".seat").droppable({
    accept: ".seat",
    hoverClass: "ui-state-hover",
    drop: function(event, ui) {

        var draggable = ui.draggable,
            droppable = $(this),
            dragPos = draggable.position(),
            dropPos = droppable.position();

        draggable.css({
            left: dropPos.left + 'px',
            top: dropPos.top + 'px'
        });

        droppable.css({
            left: dragPos.left + 'px',
            top: dragPos.top + 'px'
        });
        draggable.swap(droppable);
    }
});

});
</script>
  • 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-27T14:27:40+00:00Added an answer on May 27, 2026 at 2:27 pm

    I resolved this with $(ui.helper).hide(); in the drop function.

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

Sidebar

Related Questions

I'm using jQuery UI's draggable and droppable libraries in a simple ASP.NET proof of
How do I make an element, e.g. a div, draggable using jQuery?
I'm creating a day planner using jquery, draggable and droppable. When a job is
I am using jQuery droppable (in conjunction with jQuery draggable ) to allow the
I'm using JQuery's Sortable (not Draggable or Droppable) and I was wondering how I
I'm using the Draggable/Droppable functionality of Jquery to allow drag-and-drop from a TreeView to
Using jQuery and Jquery UI, I have a draggable and droppable area, the draggable
I am using draggable and droppable features of jquery-ui. I need to identify whether
I am using class for setting draggable and droppable properties of the element (UL,
Using jquery how do I focus the first element (edit field, text area, dropdown

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.