Why can't I get Draggable ID when Dropped in a

2019-09-09 21:51发布

I am having a problem getting ui.draggable to work. I am hoping to be able to return its ID. All it returns is undefined, which I do not understand.

Here is my droppable call....

$( ".currqcontainer" ).droppable({ 
    accept: ".currqwrapper",
    drop: function (ui, event) {
        alert("dropped");
        var testid = $(ui.draggable).attr('id');
        alert(testid);
    }   
});

Here is my draggable initialization...

$( ".currqwrapper" ).draggable({ revert: "invalid" });

I am creating the currqwrapper instances with this script.

var $div = $("<div/>", {id: objectID, class: "currqwrapper", text: question});          
$("#currQ" + (i+1)).append($div);

If any of you could tell me why I am not correctly able to read the ID that would be great. Obviously I can provide anything else you need as well!

HERE IS MY CONSOLE.LOG(UI)It has the ID I need in there #ZiuFEYAcpP but I am not sure how to call it out? I notice it is in the toElement...

toElement: div#ZiuFEYAcpP.currqwrapper.ui-draggable.ui-draggable-handle
accessKey: ""
align: ""
attributes: NamedNodeMap
0: id
baseURI: null
childNodes: NodeList[1]
firstChild: text
baseURI: null
childNodes: NodeList[0]
data: "ZiuFEYAcpP"
firstChild: null
lastChild: null
length: 10
localName: null
namespaceURI: null
nextElementSibling: null
nextSibling: null
nodeName: "#text"
nodeType: 3
nodeValue: "ZiuFEYAcpP"

1条回答
干净又极端
2楼-- · 2019-09-09 22:22

You have reversed the parameters on the drop event. instead of

drop: function (ui, event) {...

write

drop: function (event, ui) {
查看更多
登录 后发表回答