When a draggable item is added to a droppable using droppable.append(draggable), the draggable item vanishes

Currently, I am utilizing JQuery draggable/droppables to enable dragging divs from one container to another and having them become children within the new container. Although the HTML reflects the movement, the div disappears from the screen upon releasing it into the target area.

Visit this link for reference

    <div id="left" class="droppable">
    <div class="draggable">1</div>
    <div class="draggable">2</div>
    <div class="draggable">3</div>
    <div class="draggable">4</div>
</div>
<div id="right" class="droppable">drag blocks in here</div>

JQuery

$('.draggable').draggable();

$(init);

function init() {
  $('.draggable').draggable();
  $('.droppable').droppable({
    drop: handleDropEvent
  });
}

CSS

.draggable {
    width:50px;
    height:50px;
    background:gray;
    padding:5px;
    margin:5px;
    border-radius:10px;
    z-index:100;
    display:block;
}
.droppable {
    box-sizing:border-box;
    border:2px solid black;
    width:50%;
    float:left;
    min-height:300px;
}

Answer №1

Check out this example that demonstrates how to achieve what you're looking for.

http://jsfiddle.net/tqqLxquL/7/

When the element is dragged and dropped, it initially has a left property which needs to be overridden.

    function handleDropEvent( event, ui ) {
       console.log($(ui.draggable[0]));
       var $draggable = $(ui.draggable[0]);  
       $draggable.appendTo(this);
         $draggable.css({
            left: 0
         })
    }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Can someone please show me how to position this H1 in the center at the bottom of the div?

Looking for a simple solution to place text at the bottom of a div without turning the entire div into a grid. New to HTML/CSS and struggling with vertical alignment issues... <!DOCTYPE html> <html> <head> <title>Creating an O ...

How to set up objects with accessors and mutators in ES5 JavaScript?

creating a new object, obj1, with an enumerable property of value 42 > changing the value of obj1.property to 56 > output: 56 > accessing obj1.property returns: 42 When using use strict, an error occurs. To merge multiple objects: using jQuery ...

Will using lengthy CSS custom property names impact the performance of a website?

I've been contemplating experimenting with projects that aim to shorten CSS variables in order to decrease the size of my CSS file. How do long CSS custom property names impact page performance? Reduction in CSS file size (including compression) Imp ...

What is the most effective method for delivering npm packages using django?

Currently, I am utilizing django as the backend along with a few javascript packages installed via npm. To access these packages, I have configured django to serve /node_modules by including it in the STATICFILES_DIRS. While this setup has been functional, ...

Using javascript to color in cells of a grid of "pixels"

I have a project similar to an Etch-a-Sketch in progress. The main challenge I am currently facing is how to gradually darken each cell of the grid with every pass of the mouse cursor, based on the opacity of the cell being hovered over. When the grid cell ...

Looking to limit the size of the content to fit within the parent column's dimensions [using Twitter Bootstrap]?

One of the main challenges I'm facing is that the contents inside the bootstrap columns are not scaling properly to fit the size of their respective columns. Here's the layout I'm aiming for: 1 This page consists of two separate columns: ...

Having trouble with inserting information into MariaDB with Node.js

const mariadb = require('mariadb/callback'); const connection = mariadb.createConnection({ host : 'localhost', user : 'tudublin', password : 'Tudublin@2020', database : 'IOT', timezone: &a ...

Retrieving complete credit card information with the help of JavaScript

I've been grappling with extracting credit card data from a Desko Keyboard, and while I managed to do so, the challenge lies in the fact that each time I swipe, the card data comes in a different pattern. Here is my JavaScript code: var fs = require ...

Calculate the average color of the outer pixels in an image

I am looking to dynamically set the background color of a div using the average color of the outer pixels in an image. This way, I can avoid manually setting the background color for each image. For example, if the image is 100px x 100px, I would check th ...

Retrieving custom attribute values during a drop event in Jquery drag and drop operations

I'm currently working on a moodboard creator, but I've hit a snag while trying to transfer the values from custom attributes of an image to a new div once the drop action is completed. Every time the drop is finished, it always fetches the value ...

Error in Internet Explorer 9: Unable to access the 'ajax' property value as the object is either null or undefined

Issue with IE9 I am facing a challenge while trying to display a map on a webpage using Ajax data fetching. Despite working smoothly on all browsers, the map fails to load on IE9. An error message pops up: SCRIPT5007: Unable to get value of the proper ...

Circular css3 animation originating from the center

Can someone provide an example of how to create a div rotating around a circle in CSS3 while the circle itself is already rotating? I attempted to use webkit frame, but it did not work correctly. If anyone has any examples or tips on achieving this effec ...

Searching for a specific value in a dropdown list during an iteration

Currently, I am iterating over an Ajax response to populate a JSON object in a select box. However, some of the JSON results may contain duplicate values. My goal is to check if a value already exists in the select box as I iterate through the loop. If a ...

Background images are not appearing in Rails production environment

There seems to be an issue with my images not showing up in the production environment (link here). Here is a snippet of my code: _header.html.erb <%if action_name == 'index' %> <div class="main_header_bg" id="main_head ...

Having trouble with executing dual actions in React, causing state to behave incorrectly

Within a component, I am faced with the challenge of dispatching two distinct actions from two separate reducers that update different states within my application. Below is some excerpt of the code snippet for the said component: onSubmit = e => { ...

Images in the JavaScript menu are not remaining fixed in place

Can someone help me with my website? I'm having trouble with the menu for different pages, it should stay gray for the active page. It was working fine before I switched to Wordpress, but now I'm not sure what the issue is. Could someone take a ...

What is preventing qUnit from sending notifications for exceptions within a frame?

When using qUnit, I've noticed that it doesn't provide any indication when an exception occurs in a later part of the test. For example, running the following code within a test(): stop(); function myfun(ed) { console.log('resumed' ...

Having trouble loading the URL into an iframe using angularJS

With AngularJS, I am attempting to dynamically load the URL address "myLink" into an iframe in another HTML file. The data.No variable is obtained from elsewhere and functions correctly (providing the necessary ID for the URL). In the controller - "Transa ...

The 'active' status in AJAX pagination is unresponsive

I am new to working with Ajax and JavaScript. How can I apply the class 'active' when a button is clicked? Below is my code snippet: $(document).ready(function(){ load_data(); function load_data(pages) { var id=& ...

Receiving Error 415: Media Type Not Supported When Making WCF Service Call via $

My current challenge involves trying to connect a WCF web service with an ASPX page. Here is the code snippet I am using: var payload = { applicationKey: 40868578 }; $.ajax({ url: "/Services/AjaxSupportService.svc/ReNotify", type: "POST", ...