javascript - Jquery put element inside another not after -
i have few images , element can drag , drop on images
<span name="imie" id="drag1" class="drag"> <img name='aa' id='test' src="http://placehold.it/80x80/c9112d/fff&text=1" width="70px" height="20px" /> </span> <span>imiÄ™</span> <div class="col droppable"> <div class="canvas"> <img class="img-bg" src="test.jpg"> </div> <div class="canvas"> <img class="img-bg" src="test.jpg"> </div> </div>
i want add dropped box inside <div class="canvas">
after or before img
. want see box on img in code should inside canvas
not after script
var counter = 0; var x = null; //make element draggable $(".drag").draggable({ helper: 'clone', cursor: 'move', tolerance: 'fit', revert: true }); $(".droppable").droppable({ accept: '.drag', activeclass: "drop-area", drop: function (e, ui) { if ($(ui.draggable)[0].id !== "") { x = ui.helper.clone(); ui.helper.remove(); x.draggable({ helper: 'original', cursor: 'move', containment: '.droppable', tolerance: 'fit', drop: function (event, ui) { $(ui.draggable).remove(); } }); x.addclass('remove'); var el = $("<span><a href='javascript:void(0)' class='xicon delete' title='remove'</a>x</span>"); $(el).insertafter($(x.find('img'))); x.appendto('.droppable'); $('.delete').on('click', function () { $(this).parent().parent('span').remove(); }); $('.delete').parent().parent('span').dblclick(function () { $(this).remove(); }); } } });
i suppose problem in x.appendto('.droppable');
. can't handle it. , whole example online here
you have make <div class="canvas"></div>
droppable not <div class="col droppable"></div>
try:
html:
<div class="col "> <div class="canvas droppable"> <img class="img-bg" src="http://formularze.iform.pl/zdjecia/formularze/4556/sf_sdfra.gif"> </div> <div class="canvas droppable"> <img class="img-bg" src="http://formularze.iform.pl/zdjecia/formularze/4556/sf_sdfra.gif"> </div> </div>
js:
$(this).append(x);
or if want before img
try:
$(this).prepend(x);
Comments
Post a Comment