Note that there are some explanatory texts on larger screens.

plurals
  1. POJquery remove not working for draggable div
    primarykey
    data
    text
    <p>On clicking a link, a div is created which is draggable. I have another link which I want to be able to use to remove this newly created div. </p> <p>Jquery code:</p> <pre><code> var counter = 0; $(document).ready(function(){ $("#alphalink").click(function(){ var name = 'element'+ counter++; $('#elementarea').prepend('&lt;div id="' + name + '"&gt;&lt;/div&gt;'); $("#" + name).prepend('&lt;img id="theImg" src="http://us.metamath.org/symbols/alpha.png" /&gt;'); $("#" + name).css("z-index", counter); $("#" + name).css("position", "absolute"); $("#" + name).draggable({ cursor: "move"}); }); $("#cleardiv").click(function(){ var olddiv= 'element'+ counter; alert(olddiv); $("#element" + counter).remove(); }); }); </code></pre> <p>HTML code:</p> <pre><code> &lt;div id="elementarea" style="width:300px; height:200px; background-color:#ccc; margin-top:10px; margin-right: 15px; float:left "&gt; &lt;p&gt;Staging area here&lt;/p&gt; &lt;/div&gt; &lt;div id ="alphalink"&gt; &lt;p&gt; Alpha Click &lt;/p&gt; &lt;/div&gt; &lt;div id ="cleardiv"&gt; &lt;p&gt; clear item &lt;/p&gt; &lt;/div&gt; </code></pre> <p>On clicking on "Alpha Link", a draggable div is created. On clicking "clear item",the div should be removed.</p> <p>However, the jquery .remove() does not seem to remove this newly created div. What is going wrong in this example?</p> <p>You can try out the entire code here - <a href="http://jsbin.com/iboxoy/95/edit#source" rel="nofollow">http://jsbin.com/iboxoy/95/edit#source</a></p>
    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.
    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