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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:21:50+00:00 2026-06-03T17:21:50+00:00

I’m quite new to JQuery but I managed to do some things on my

  • 0

I’m quite new to JQuery but I managed to do some things on my own. I have a three input fields and three options. The options can be dragged into the input fields but there can’t be two draggables into one droppable.

This works perfectly if you don’t move the draggables over the droppables. But when you go over a droppable JQuery executes the “out” event. I was hoping for a “dropout” event which can solve my problem but there isn’t one.

(There is also a problem with the “removeClass” function, because it doesn’t work. However that isn’t a big issue…).

$(function() {
    var textbox; 

    $( ".draggable" ).draggable({ 
        revert: function ( event, ui ) {
            $(this).data("draggable").originalPosition = {
                top: 0,
                left: 0
            };
            return !event;
        },
    });

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

            //check if droppabele contains draggable
            if ($(this).data("containsDrop") === 0 || $(this).data("containsDrop") === undefined) { //doesn't contain
                $(this).data("containsDrop", 1);

                ui.draggable.position( { of: $(this), my: 'left top', at: 'left top' } );
                textbox = this;

                $( this ).addClass( "ui-state-highlight" )

            } else { //contains --> go back to options
                ui.draggable.animate({ top: 0, left: 0 }, 'slow');
            }
        },
        out: function ( event, ui ) {
            $(this).data("containsDrop", 0);
            $(textbox).removeClass( "ui-state-highlight" );
        }
    });
});

I was hoping that some can take a look to at this Fiddle: http://jsfiddle.net/u7aJ7/10/

Thanks in advance.

  • 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-03T17:21:51+00:00Added an answer on June 3, 2026 at 5:21 pm

    I spend a few hours on it and worked out the following solution.

    You can check a working example on http://jsfiddle.net/s5057285/yx3gW/

    if ($("div.draggable").length > 0) {
        $("div.draggable").draggable({
            //callback 
            revert: function(droppableObj) {
                if (droppableObj === false) {
                    //revert to original position
                    $(this).data("draggable").originalPosition = {
                        top: 0,
                        left: 0
                    };
                    var textbox = $(this).data("droppable");
                    $(textbox).width(74);
                    $(textbox).val('');
                    $(this).removeClass("dropped");
    
                    positionDraggables();
    
                    return true;
                } else {
    
                    positionDraggables();
    
                    return false;
                }
            }
        });
    }
    
    if ($("div.draggable").length > 0) {
        $("input.droppable").droppable({
            drop: function(event, ui) {
                //postition of draggable is the same as droppable
                ui.draggable.position({
                    of: $(this),
                    my: 'left top',
                    at: 'left top'
                });
                //text from draggable in textfield
                $(this).draggable("widget").val(ui.draggable.text());
                //store the droppable in the draggable
                ui.draggable.data("droppable", this);
                ui.draggable.addClass("dropped");
                //change width and height to size of draggable
                $(this).width(ui.draggable.width());
                $(this).height(ui.draggable.height());
            }
        });
    }
    
    function positionDraggables() {
        var selects = $('body').find('div.options');
        selects.each(function(index, el) {
            var children = el.children;
            for (var i = 0; i < children.length; i++) {
                var child = children[i];
                if ($(child).hasClass("dropped")) {
                    var textbox = $(child).data("droppable");
                    $(child).position({
                        of: $(textbox),
                        my: 'left top',
                        at: 'left top'
                    });
                }
            }
        });
    }​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I need to clean up various Word 'smart' characters in user input, including but
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text

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.