How to get lost id element in jQuery event

When I drop something in jquery droppable, I want to get the id of the fallen elements. When I did it like this:

$("#here").droppable({ tolerance: 'fit', accept: ".one", drop: function(){ id = $(this).attr("id"); alert (id); } }); 

he, of course, warned id about inaccessibility here . How can I select the id of the dumped div?

+6
source share
2 answers

Change the drop function to accept two arguments: event, ui

 function(event,ui){ var draggable = ui.draggable; var id = draggable.attr("id"); } 

A draggable that is dropped is represented by ui.draggable

Found in jquery ui docs for droppable.

+7
source

This worked for me:

  $( "#droppable" ).droppable({ drop: function( event, ui ) { var draggableId = ui.draggable.attr("id"); var droppableId = $(this).attr("id"); } }); }); 
+2
source

Source: https://habr.com/ru/post/890027/


All Articles