Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First, please fix your code indentations.</p> <p>There are some mistakes on your code:</p> <ol> <li><p><code>var i = 0;</code> I think it should be a global variable. So put it outside your <code>$(document).ready(function() {})</code> block;</p></li> <li><p>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 <code>$('#shoppingCart ol').droppable({...})</code> in <code>$(document).ready(function() {})</code> block you try to add <code>droppable</code> to an element that even not in your page, so this won't do a thing.</p></li> </ol> <p>What you should do is make the element <code>droppable</code> <strong>after</strong> you create that element and put it on your page. here's an example:</p> <pre><code>$("button[id='columnadd']").click(function () { // create the element var domElement = $('&lt;aside id="shoppingCart' + i++ + '" class="shoppingCart"&gt;&lt;h2 class="ui-widget-header"&gt;Add Menu Items Here&lt;/h2&gt;&lt;aside class="ui-widget-content" id="droppable"&gt;&lt;ol&gt;&lt;li class="placeholder"&gt;Add your items here&lt;/li&gt;&lt;/ol&gt;&lt;/aside&gt;&lt;/aside&gt;'); // 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); } }); }); </code></pre> <p>and this is the function to make your dropped element has its own placeholder</p> <pre><code>function makeItDroppableToo(e, ui, obj) { $(obj).find(".placeholder").remove(); var placeholder = $("&lt;ol&gt;&lt;li class='placeholder'&gt;You can also drop it here&lt;/li&gt;&lt;/ol&gt;"); $("&lt;li&gt;&lt;/li&gt;").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); } }); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload