Following @amphetamachine advice from this question I was able to handle nested clicks using jQuery. Now the drag feature that was previously working is now not working after implementing the delegates.
The concept still the same an empty DIV that once it will it will add another DIV inside itself and if that created DIV is click it is then remove. I use a variable to determine if I want to drag the DIV or to remove it.
HTML
<div id="container"></div>
jQuery
$('#container').on('click', function(e){
// Add other DIV
$( this ).append('<div class="other">XYZ</div>');
e.stopPropagation();
// Remove other DIV
$('div.other').bind('click', function(event){
if (global_variable == 'drag') {
$( this ).draggable({cursor:'move'});
}
else {
$( this ).remove();
}
event.stopPropagation();
});
});
What am I missing?