Skip to content
Advertisement

Drop Event Not Preventing Default

I’ve the following: http://jsfiddle.net/KywJT/

function dragEnter(evt) {
    evt.stopPropagation();
    evt.preventDefault();
    $(evt.target).addClass('over');
}

function dragLeave(evt) {
    evt.stopPropagation();
    evt.preventDefault();
    $(evt.target).removeClass('over');
}

function drop(evt) {
   evt.stopPropagation();
   evt.preventDefault();
   $(evt.target).removeClass('over');
}

jQuery( function ( $ ) {

  var $box = $( "#box" );
  $box.bind("dragenter", dragEnter);
  $box.bind("dragleave", dragLeave);
  $box.bind("drop", drop);
});

I’m using Chrome version 24.0.1312.52 m and last jQuery (1.8.3). When I drop a file into the box, browser is not preventing default beaviour. Can you please help me?

P.S. dragexit is deprecated correct?

Advertisement

Answer

This should fix the issue for you.

jQuery( function ( $ ) {
    var $box = $( "#box" );
    $box.bind("dragenter", dragEnter);
    $box.bind("dragleave", dragLeave);
    $box.bind("drop", drop);

    $(document).bind('dragover', function (e) {
         e.preventDefault();
    });
});
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement