开发者

How to get the dropped item's id on drop event jquery

开发者 https://www.devze.com 2023-03-11 22:31 出处:网络
When I drop something to jquery droppable, I want to get the dropped items\' id. When I did it like this:

When I drop something to jquery droppable, I want to get the dropped items' id. When I did it like this:

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

it开发者_开发知识库 of course alerted the id of the droppable here. How can I select the id of the dropped div?


Change your drop function to take two arguments: event, ui

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

The draggable that is being dropped is represented by ui.draggable

Found in the jquery ui docs for droppable.


This worked for me:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号