0
votes

I'm trying to move links (.link) from one div (.folder) to another but the drop event is not firing. I think I made all .link divs droppable areas by preventing default behaviour in dragenter and dragover events. Here's the code:

$(document).ready(function() {
    //Logic for create folder button
    $("#create-folder-button").click(createFolder);

    // //Logic for drag and drop for the links
    $(".folder").on("dragstart", function(e) {
        console.log("dragstart");
    });
    $(".folder").on("dragenter dragover", function(e) {
        e.preventDefault();
    });
    $(".folder").on("drop", function(e) {
        e.preventDefault();
        console.log("drop");
    });
});

The "dragstart" prints but the "drop" doesnt.

1
please a fiddle and also explain what you are expecting ? - Raghvendra Kumar
Right now I would just like it to print the "drop". I have several divs with class "folder" and <a>s inside them. I would like to move them around the divs. - Joaquim Ferrer
Is this code wrapped in a $(document).ready(){ }? If not, and this comes before folder is defined, that could be the problem. - LAROmega
It is. The "dragstar" prints but the drop doesn't. - Joaquim Ferrer

1 Answers

1
votes

You need to use event.stopPropagation():

$(".folder").on("drop", function(event) {
    event.preventDefault();  
    event.stopPropagation();
    alert("Dropped!");
});