I am trying to use .bind()
with 'dragenter'
, 'dragover'
, and 'drop'
so I can drag a file from my desktop to my browser.
Please see attached jsfiddle. http://jsfiddle.net/v82An/23/
$(function(){
function dragenter(e) {
e.stopPropagation();
e.preventDefault();
}
function dragover(e) {
e.stopPropagation();
e.preventDefault();
}
function drop(e) {
e.stopPropagation();
e.preventDefault();
alert('hi')
}
$('#drop').bind('dragenter', dragenter, false);
$('#drop').bind('dragover', dragover, false);
$('#drop').bind('drop', drop, false);
});
This fiddle attaches these events properly in 1.5, but in 1.6 they simply don't work.
Anyone know if I'm just doing it wrong?
It seems to work if you don't set
preventBubble
tofalse
:DEMO
Update: If you look at the documentation, passing three parameters where the last one is a boolean, is interpreted as:
which means that the handler is not used as event handler but as event data.
They changed how they detect the handler though. In jQuery 1.5.2, it was:
You see, when the second argument was a function, then this one was used as event handler (instead of the third one).
But it was changed in jQuery 1.6.2 to:
Now it is only tested how many arguments are passed. As, in your case,
data
is notfalse
(it is a function) and you pass three arguments,fn
is not changed. It staysfalse
.When the handler is
false
, then this happens:So this could actually be seen as bug in jQuery 1.5 which is now fixed and is not a problem with these particular events.