jquery ui get exact dropped element

107 Views Asked by At

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.

1

There are 1 best solutions below

0
n44s On BEST ANSWER

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
            }

        },
    });