I am just getting started with this, but I am wondering how could I take the very simple example below and modify so that if the draggable div is already placed on the droppable div it won’t fire the alert.
<script type="text/javascript">
$(function () {
$("#draggable-1").draggable();
$("#draggable-2").draggable();
$("#droppable").droppable({
drop: function (event, ui) {
var currentId = $(ui.draggable).attr('id');
if (currentId == "draggable-1") {
$(this)
// would like to prevent this if draggable is already dropped!
alert("Adding Item #1.")
} else {
$(this)
alert("Adding Item #2.")
}
}
});
});
</script>
<table width="100%"><tr><th>Draggable</th><th>Order Section</th><tr><td>
<div id="draggable-1">
<p>Item #1</p>
</div>
<div id="draggable-2">
<p>Item #2.</p>
</div>
<div id="droppable">
<p>Add Your Item</p>
</div>
One solution that worked for me:
And so forth. The idea is that the draggable fires the alert, if: