I am trying to make a drag and drop feature from table1
to table2
and want to make sure the dropped table2
cell is empty when the user drag table1
itme. If the table2
cell is empty, then I can drop it otherwise it will return to the table1
.
var dragging =null;
td = $('.table td');
$(td).draggable({
cursor:'pointer',
snap:$('td:empty')
})
$(td).droppable({
drop:function(event, ui){
if($(this).text()=='') { // $(this).is(':empty:) doesn't work either
console.log('drop now!')
}else{
console.log('not empty') //revert
}
}
})
I am not sure how to revert the dragged item back to table1
and how to detect if the dropped cell already has data.
Any helps? Thanks a lot!