Saturday, May 25, 2024
 Popular · Latest · Hot · Upcoming
168
rated 0 times [  170] [ 2]  / answers: 1 / hits: 70386  / 11 Years ago, fri, january 24, 2014, 12:00:00

It seems the drop event is not triggering when I would expect.



I assume that the drop event fires when an element that is being dragged is releases above the target element, but this doesn't seem to the the case.



What am I misunderstanding?



http://jsfiddle.net/LntTL/



$('.drop').on('drop dragdrop',function(){
alert('dropped');
});
$('.drop').on('dragenter',function(){
$(this).html('drop now').css('background','blue');
})
$('.drop').on('dragleave',function(){
$(this).html('drop here').css('background','red');
})

More From » jquery

 Answers
5

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.


[#72959] Thursday, January 23, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
elliem

Total Points: 415
Total Questions: 117
Total Answers: 94

Location: American Samoa
Member since Fri, Aug 26, 2022
2 Years ago
;