how to get the id of droppable item using sortable

How can I get the id of the item where a dragged item is to be dropped instead, using sortable. I can get the ID of the dragged item but can't get the ID of the item to be dropped instead. Here is my code for what have I tried so far:

$(function () {
$('#sortable').sortable({
    //to prevent items from moving around when draging
    containment: "parent",
    start: function (event, ui) {
        // get the initial position(index) of item
        var start_pos = ui.item.attr('id');
        ui.item.data('start_pos', start_pos);

   },

    update: function (event, ui) {
        var index = ui.item.index();//position of dropped
        var start_pos = ui.item.attr('id');//position of dragged
        alert(start_pos);
        alert(index);

        // Iterate over all <li> elements
        $.each($('#sortable li'), function (idx, item) {

           // $(item).html(html + ' - ' + (idx + 1));
        });
    },
    axis: 'y'
});

for example, if I'm dragging the item from position 1 to position 5 I want to alert 1 and 5

Answers


Try the below code :-)

$('.selector').droppable({ drop: Drop });

function Drop(event, ui) {
  var draggableId = ui.draggable.attr("id");
  var droppableId = $(this).attr("id");
}

Need Your Help

Sha-1 Alghoritm gives different output on the same input

java sha1

public void actionPerformed(ActionEvent e) {

How to use common Layout and styles across multiple Asp.net MVC applications

asp.net-mvc layout razor asp.net-mvc-4 telerik-mvc

I have a visual studio solution with multiple telerik MVC4 razor projects having same look and feel. I don't want to have same layout, CSS/styles, images and js files copied in all MVC4 projects. W...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.