In JavaScript you can define so called event listeners.
This means basically the elements, eg your image, is waiting for something to happen – e.g. when it gets dragged. This would be a drag
event.
When you then move the mouse to another cell, and drop the image, this would be a drop
event.
Please have a look at the documentation, there is even a complete example.
https://developer.mozilla.org/en-US/docs/Web/API/Document/drag_event