Drop event not firing in chrome
In order to have the drop event occur on a div element, you must cancel the ondragenter
and ondragover
events. Using jquery and your code provided...
$('.drop').on('drop dragdrop',function(){ alert('dropped');});$('.drop').on('dragenter',function(event){ event.preventDefault(); $(this).html('drop now').css('background','blue');})$('.drop').on('dragleave',function(){ $(this).html('drop here').css('background','red');})$('.drop').on('dragover',function(event){ event.preventDefault();})
For more information, check out the MDN page.
You can get away with just doing an event.preventDefault()
on the dragover
event. Doing this will fire the drop
event.
In order for the drop event to fire, you need to assign a dropEffect during the over event, otherwise the ondrop event will never get triggered:
$('.drop').on('dragover',function(event){ event.preventDefault(); event.dataTransfer.dropEffect = 'copy'; // required to enable drop on DIV})// Value for dropEffect can be one of: move, copy, link or none// The mouse icon + behavior will change accordingly.