Jqueryui - Draggable loses id attribute when dragging to sortable

I use jqueryui draggable and sortable functions. My jqueryui version is 1.9.1 and the jquery version is 1.7.1.

I have a set of elements that I make draggable, and a container that can be sorted. I am dragging and dropping elements into a sortable container and want to read the id attribute of the dragging element in a sortable break handler. However, the identifier is undefined there.

$(sortableselector).sortable({ stop: function(event, ui) { alert(ui.item.attr('id')); } }); $(draggableselector).draggable({ revert: true, revertDuration: 0, connectToSortable: 'sortableselector', }); 

outputs undefined. I saw several messages indicating this error, but was not resolved. How can I get a draggable object id?

+7
source share
1 answer

Try ...

 $(sortableselector).sortable({ stop: function(event, ui) { alert(ui.item[0].id); } 

});

-2
source

All Articles