I am trying to detect which cell an object is being dropped into.
<table>
<tr>
<td class="weekday">Sun</td>
<td class="weekday">Mon</td>
<td class="weekday">Tue</td>
<td class="weekday">Wed</td>
<td class="weekday">Thu</td>
<td class="weekday">Fri</td>
<td class="weekday">Sat</td>
</tr>
<tr>
<td class="droppable"> </td>
<td class="droppable"> </td>
<td class="droppable"> </td>
<td class="droppable"> </td>
<td class="droppable"> </td>
<td class="droppable"> </td>
<td class="droppable"> </td>
</tr>
</table>
<div class="draggable">Drag Me</div>
On drop, how do I determine which day the div was dropped into?
I couldn't get dropping to work inside of cells - I even tried putting divs inside each of the cells. If you drop the draggable div into the droppable div this code will work:
It'd be a lot easier if you made the
weekday
cells droppable — then you don't have to calculate the index of the current dropped cell and look up the contents of the day-of-the-week cell.Also, I think you need to give the cells a width and height in the CSS.
This seems to do what you want, courtesy of the jQuery UI docs: