I have a draggable div(using jqueryui plugin for this) inside a table. I am able to drag a single div and keep it contained inside <td id=” middle-side”></td>. Now I am having issues trying to create additional divs that will be also be draggable and contained inside the <td id=” middle-side”></td>. The button I am using to append this new div is not reacting to the click. How would I be able to add new dragagble divs to <td id=” middle-side”></td>? JSFIDDLE
Html
<td class="middle-side">
Keep me inside here!
<div class="draggable" class="ui-widget-content">
<p><b>Drag me around</b></p>
</div>
</td>
Jquery
//To Drag
$(function() {
$( ".draggable" ).draggable({ containment: "parent" });
});
//To Add New Div
var i = 0;
var remove = true; // added this
$('#button').click(function(e) {
$('<div/>').attr({
'id' : i
}).addClass('draggale').css({
'top' : e.pageY - 20,
'left' : e.pageX - 20
}).appendTo('.middle-side');
i++;
});
$('.middle-side').on('click','.draggable',function (){ // corrected spelling
if(remove){
$(this).remove();
} else {
//just to see if it was clicked
$(this).css({'background-color': 'red'});
}
});