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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:54:59+00:00 2026-06-13T12:54:59+00:00

Hi all i have a function where i have to drag and drop elements

  • 0

Hi all i have a function where i have to drag and drop elements here is my code:

$(document).ready(function() {

    var i = 0;
    $("button[id='columnadd']").click(function () {
        alert(1);
            var domElement = $('<aside id="shoppingCart' + i + '" class="shoppingCart"><h2 class="ui-widget-header">Add Menu Items Here</h2><aside class="ui-widget-content" id="droppable"><ol><li class="placeholder">Add your items here</li></ol></aside></aside>');
            i++;
            $(this).after(domElement);
    });

        $(".small_box li" ).draggable({
            appendTo: "body",
            helper: "clone"
        });
});

$('#shoppingCart ol').droppable({
    accept: '.small_box li',
    drop: function (event, ui) {
        alert(1);
        $(this).find(".placeholder").remove();
        $("<li></li>").text(ui.draggable.text()).appendTo(this);
    }
});

here is my html:

    <aside class="small_box">
    <h4>BRANDS</h4>
    <ul>
        <li id ="brand1"><a class="" href="#">Brand1</a></li>
        <li id ="brand2"><a href="#">Brand2</a></li>
        <li id ="brand3"><a href="#">Brand3</a></li>
        <li id ="brand4"><a href="#">Brand4</a></li>
     </ul>
    </aside>

i should be able to drop in at this place <li class="placeholder">Add your items here</li>

var domElement = $('<aside id="shoppingCart' + i + '" class="shoppingCart"><h2 class="ui-widget-header">Add Menu Items Here</h2><aside class="ui-widget-content" id="droppable"><ol><li class="placeholder">Add your items here</li></ol></aside></aside>');

any help is much appreciated

  • 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-13T12:55:00+00:00Added an answer on June 13, 2026 at 12:55 pm

    First, please fix your code indentations.

    There are some mistakes on your code:

    1. var i = 0;
      I think it should be a global variable. So put it outside your $(document).ready(function() {}) block;

    2. You create a DOM Element (which is the drop area) upon click and this element is not in your page until you click the trigger. By doing $('#shoppingCart ol').droppable({...}) in $(document).ready(function() {}) block you try to add droppable to an element that even not in your page, so this won’t do a thing.

    What you should do is make the element droppable after you create that element and put it on your page. here’s an example:

    $("button[id='columnadd']").click(function () {
      // create the element
      var domElement = $('<aside id="shoppingCart' + i++ + '" class="shoppingCart"><h2 class="ui-widget-header">Add Menu Items Here</h2><aside class="ui-widget-content" id="droppable"><ol><li class="placeholder">Add your items here</li></ol></aside></aside>');
    
      // put it after $(this)
      $(this).after(domElement);
      // at this point you have domElement in your page
    
      // make it droppable
      domElement.find("ol").droppable({
        // put options here
        greedy: true,
        drop: function (event, ui) {
          makeItDroppableToo(event, ui, this);
        }
      });
    });
    

    and this is the function to make your dropped element has its own placeholder

    function makeItDroppableToo(e, ui, obj) {
      $(obj).find(".placeholder").remove();
    
      var placeholder = $("<ol><li class='placeholder'>You can also drop it here</li></ol>");
      $("<li></li>").append(ui.draggable.text()).append(placeholder).appendTo($(obj));
    
      // this is the same as the previous one
      placeholder.droppable({
        // put options here
        greedy: true,
        drop: function (event, ui) {
          makeItDroppableToo(event, ui, this);
        }
      });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three classes that all have a static function called 'create'. I would
The title more or less says it all: I have a function which takes
I recently learned that all stl containers have swap function: i.e. c1.swap(c2); will lead
I have a function that iterates through all HDD's on a computer, and returns
I have a function that restores all of the default settings of my application.
I have this function to edit all fields that come from the form and
I have this function that converts all special chars to uppercase: function uc_latin1($str) {
I have a function that locks all files in a certain folder: function lockFolder_files($folder='',$task=''){
I have this function that prints the name of all the files in a
I have a function CheckMobile(MobNumber) and it will check all duplicate record of MobNumber

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.