Issues concerning placing an item on the card

When I click the "Add a Card" button to add a card to the in-box list, the card becomes sortable between different lists. This functionality works correctly. However, an issue arises when attempting to drag an item from the member list and drop it onto the card - this action does not work as expected.
Here is a Demo

HTML:

<body>
    <div id="wrapper">
        <div id="inboxList" class="cellContainer">
            <p style="display: inline;">Inbox</p>
            <button id="AddCardBtn">
                Add A Card...
            </button>
            <div id="userAddedDiv"></div>
        </div>
        <!--Member list-->
        <div id="members" class="cellContainer">
            <br style="line-height: 23px" />
            <p>Members</p>

            <div class="draggable">1</div>
            <div class="draggable">2</div>
            <div class="draggable">3</div>
        </div>
        <div id="onHoldList" class="cellContainer">
            <p>On Hold</p>
        </div>
        <div id="Done" class="cellContainer">
            <p>On Hold</p>
        </div>

    </div>
</body>

Jquery:

$(function () {
        $('.cellContainer').sortable({
            items: '.sortable-div',
            containment: 'document',
            cursor: 'crosshair',
            opacity: '0.70',
            connectWith: '.cellContainer',
            hoverClass: '.border'
        });
    });

     $(".draggable").draggable({ revert: "invalid", snap: "true", snapMode: "inner", helper: 'clone' });

    $(".sortable-div").droppable({
        accept: '.draggable',
        drop: function (event, ui) {
            ui.helper.css('top', '');
            ui.helper.css('left', '');
            $(this).find('.bottom').prepend(ui.helper);
        }
    });

CSS:

#members, #onHoldList, #Done {
    width: 275px;
    height: 230px;
    background-color: #f0f0f0;
    border: 1px solid black;
    margin-left: 1%;
    margin-top: 0.4%;
    border-radius: 10px;
    box-shadow: 7px 7px 7px #828282;
    overflow: auto;
}
#inboxList {
    width: 275px;
    height: 230px;
    background-color: #f0f0f0;
    border: 1px solid black;
    margin-left: 0.5%;
    margin-top: 0.4%;
    border-radius: 10px;
    box-shadow: 7px 7px 7px #828282;
    overflow: auto;
}

.cellContainer .sortable-div {
    background: red;
    width: 260px;
    height: 150px;
    margin-left: 2.3%;
    border-radius: 10px;
    border: 2px solid black;
    box-shadow: 0px 7px 7px #828282;
    margin-bottom: 1%;
}
.draggable {
   display:inline-block;
   border:1px solid blue;
   height: 50px;
   width: 50px;
   margin-right: 1px;
   text-align: center;
   vertical-align: center;
}

 .bottom {
    position: absolute;
    bottom: 0;
    height:25px;
    width:150px;
}

Answer №1

The issue arises from the fact that items are being created dynamically without enabling the droppable feature automatically. To resolve this, make sure to attach the droppable functionality when creating a new element.

In order to manage the sortable aspect of the board upon dropping an item, it is advisable to clone the element and adjust its position to relative.

Example Code:

$('#AddCardBtn').click(function () {
    var numberOfDiv = [100];

    with(document) {
        var $newDiv = $('<div />').addClass('sortable-div');
        $('#userAddedDiv').append($newDiv)

        $newDiv.droppable({
            accept: '.draggable',
            drop: function (event, ui) {
                $(this).append($(ui.helper).clone().css({position: 'relative', top: '0', left:'0'}));
            }
        });

        for (var i = 0; i < numberOfDiv; i++) {
            numberOfDiv[i] = $newDiv;
        }
    }
});

See a working demo here: http://jsfiddle.net/IrvinDominin/zjBP2/

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

JavaScript: Update Div Background Automatically

My website has an advertisement section that works fine for most users. However, if a user has an ad-blocker enabled, the advertisement doesn't display and instead, an empty area appears on the site. To address this issue, I plan to add a background ...

Creating PDF from HTML in Angular 2: A Step-by-Step Guide

Is there a way to create a download button within my angular2 project that allows users to save HTML div content as a PDF file? Below is the HTML content that needs to be saved as a PDF: <div id="obrz"> <br><br> <p class="float-r ...

Javascript code that enables me to specify the type of weather

My intention with this code was to create unique characteristics for different weather types and randomly select one by generating a random number. I defined 11 different weather types as objects of the Weather class. I then implemented a getWeather funct ...

How to handle untagged strings while web scraping with BeautifulSoup (bs4) technology?

While utilizing bs4 for web scraping, I encountered an issue. I was able to extract the desired strings within tags without any problems, but there is one string that doesn't seem to have any associated tags (or maybe I missed it). The structure of ...

alteration of textbox upon selection

I am currently working with the following code: $sql="SELECT * from customer_billing where sequence = '".$_GET["seq"]."' "; $rs=mysql_query($sql,$conn) or die(mysql_error()); $result=mysql_fetch_array($rs); ?> <script type= ...

Python Selenium test on AngularJS UI slider implemented

I've been experimenting with setting up a UI slider (Label=ON/OFF, Slider, Apply button) using Angular JS in combination with selenium. Here's an example of the code I've been working on: jsfiddle In my attempts, I tried using the followin ...

Locate the child element that has a particular class assigned to it

I need help writing a code to search through all children elements in order to find a div with a specific class. Unfortunately, the DIV I am looking for does not have an ID. Below is the sample HTML that I will be working with: <div class="outerBUB ...

WordPress Migration Causing Issues with Custom Font Display

I recently moved my website from to using the Duplicator plugin, but I'm facing an issue with the custom font 'Kanit' not displaying correctly. I have double-checked on the backend and confirmed that Kanit font is properly set up. Below i ...

What are the best ways to ensure that my side menu, bottom buttons, and content are all responsive

I have been struggling with creating a responsive side menu in my HTML code. Despite my efforts, the side menu contents, buttons, and layout do not adjust properly when resizing the browser window. When I drag the browser size from bottom to top, the butto ...

Capture audio using a web browser

Currently working on a project to create a platform for recording sounds. I'm aiming to incorporate a meter that measures the volume of the sound. Despite extensive research, I haven't been able to discover an HTML5 solution compatible with all b ...

Renewing Masonry and JQuery

Currently implementing Masonry from into a project aimed at creating a timeline effect for user interaction. The goal is to automatically refresh the page at intervals (every 10 seconds during testing), but encountered an issue. Upon initial load, the ge ...

Identifying the End of Rendering in Three.js

Is there a way to accurately determine when rendering has been completed? I attempted the following method: scene.add( mesh ); render(); mesh.onBeforeRender = function(renderer, scene){ ... } mesh.onAfterRender = function(renderer, scene){ ... } Ho ...

Having an issue with Vue Router in Vue 2.0, encountering an error

I encountered the following error message: [Vue warn]: Unknown custom element: <router-view> - did you register the component correctly? For recursive components, make sure to provide the "name" option. I double-checked that the Vue router ...

Refresh a particular element using javascript

I'm new to Javascript and I am trying to refresh a specific element (a div) using only Javascript when that div is clicked. I came across the location.reload() function, but it reloads the entire page which doesn't fit my requirements. Upon clic ...

Using Jquery to effortlessly toggle, fade, and animate elements on

I am using a toggle button to show/hide content on my page. My aim is to toggle the content from the #circleBtn, with a specific animation for each element. I want the #logo to "toggle up" and fade out, while the #content div toggles left and fades out w ...

I'm looking to incorporate a hover effect on a hyperlink within JEditorPane utilizing Swing in Java. How can I achieve this

After successfully implementing the hyperlink in jEditorPane through this link, I now aim to incorporate a hover effect to the hyperlink. I attempted to apply CSS using the following code: MyHTMLEditorKit kit = new MyHTMLEditorKit(); setEditorKitForConten ...

Unable to execute JS script to navigate back to prior page with webdriver

Here is my code snippet: JavascriptExecutor jse = (JavascriptExecutor)driver; jse.executeScript("window.history.go(-1);"); The code above isn't working. I've tried casting the webdriver instance but it doesn't work every time. I prefer not ...

Disabling of text selection

I'm attempting to prevent text from being selected within a div using the code below. style="-webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; ...

Leveraging $implict for transferring several parameters

Need help with creating a recursive template that can accept multiple parameters: <ng-container *ngTemplateOutlet="testTemplate; context: {$implicit:jsonObj1}"> </ng-container> <ng-template #testTemplate let-Json1> </ng-template> ...

php utilizing ajax for handling multiple data requests

I'm encountering an issue with fetching multiple data using ajax. Whenever I try to increase the quantity of items in my cart, it crashes. It works fine with a single data parameter, but when I attempt to use multiple parameters, I get strange large ...