-1

How to get the exact dropped elelement with jquery ui droppable

I have 2 or more elements overlay.

And when I drop an element jquery ui run the "drop" event for each element no juste the element I've drop.

n44s
  • 443
  • 4
  • 18

1 Answers1

0

Ok I found this solution

I add the hovered class and when is dropped I check if my element has this class

    $(".droppable").hover(
        function () {
            $(this).addClass('hovered')
        }, function () {
            $(this).removeClass('hovered')
        },
    );

    $('.droppable').droppable({
        refreshPositions: true,
        greedy: true,
        tolerance: "touch",
        drop: function (event, ui) {
            var draggedElement = ui.draggable;
            var droppedElement = $(this);
            if(droppedElement.hasClass('hovered')) {
                console.log('droppable')
                // drop my element
            }

        },
    });
n44s
  • 443
  • 4
  • 18