Search code examples
jqueryjquery-ui-draggablejquery-ui-droppable

Jquery droppable with ondrop callback associated to draggable


There is one onDrop function associated with the droppable. I have created an tree where i can drag and drop nodes to change their position in the tree. In a page where I have a list whith elements I want to associate to node by dragging on it. If I redeclare a new ondrop the one corresponding to the node stopped to work. What I would like to do is associate the onDrop function with the draggable to add new behaviour depending on what type of element is dragged.


Solution

  • If I understood your question right (hard to distinguish your aim) you want to have two different functions in drop event.

    You can do define each drop event in a namespace so event handler don't get overridden:

    $('.droppable').on('drop.FirstFunction', function (event, ui) {
         firstFunction();
    });
    
    $('.droppable').on('drop.SecondFunction', function (event, ui) {
         secondFunction();
    });