Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Instead of</p> <pre><code>$(".deleteObj").click(function () { $(this).parents('.ui-widget-content').remove(); }) </code></pre> <p>there should be:</p> <pre><code> $("#AdContainer").on('click', '.deleteObj', function () { $(this).parents('.ui-widget-content').remove(); }) </code></pre> <p>Demo: <a href="http://jsfiddle.net/mV75R/1/" rel="nofollow">http://jsfiddle.net/mV75R/1/</a></p> <p><code>.click</code> will attach event to existing elements only. And once you add new element which should have that handler, you should attach event handler to new element explicitly. Or you can use <a href="http://api.jquery.com/on/" rel="nofollow"><code>.on</code></a> like above (<a href="http://api.jquery.com/live/" rel="nofollow"><code>.live</code></a> in older versions of jQuery). It will work for newly created elements also. </p> <p>Another option is to add click event handler once you create new Image element:</p> <pre><code>$(".createObjImage").click(function () { var newObjImage = $('&lt;div id="Image" class="ui-widget-content"&gt;&lt;p class="handle"&gt;&lt;span class="deleteObj"&gt;[x]&lt;/span&gt; Image&lt;/p&gt;&lt;/div&gt;').draggable(draggableOptions).resizable(resizableOptions); $("#AdContainer").append(newObjImage); $('.deleteObj', newObjImage).click(function () { $(this).parents('.ui-widget-content').remove(); }); }) </code></pre> <p>(of course, remove object code could be moved into separate function, instead of copy/paste) Demo: <a href="http://jsfiddle.net/mV75R/2/" rel="nofollow">http://jsfiddle.net/mV75R/2/</a></p>
 

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