jquery cant get drag item id in Sortable

i am having problem in getting the id of the dragged item in "sortable", can you please help me out in this.

<script>
$(document).ready(function(){
    $("#div1,#div2,#div3").sortable({
        revert: true,
        accept: '.draggable',
        connectWith: [".sortable_div"],
        receive: function(e, ui) { 
            var item_id = $(this).attr("id");
            var drag_id = $(ui.item).attr('id')
            alert('alert:'+item_id+' of '+drag_id);
        }
    }).disableSelection();
});
</script>


<div id="div1" class="sortable_div">
<span id="span1" class="draggable"></span>
</div>
<div id="div2" class="sortable_div">
<span id="span2" class="draggable"></span>
</div>
<div id="div3" class="sortable_div">
<span id="span3" class="draggable"></span>
</div>

Answers


To get draggable item id:

var drag_id = $(ui.item).attr("id");

You can get the ID by

receive: function(e, ui) { 
   var item_id = $(this).attr("id");
   //ui.draggable.attr('id') or ui.draggable.get(0).id or ui.draggable[0].id
   var drag_id = ui.draggable.attr('id');
   alert('alert:'+item_id+' of '+drag_id);
   console.log(ui.draggable); // to see the bunch of items
}

If i understood correctly what you want to do i think you should do something like this:

var drag_id = $(event.target).attr('id')

try this dude,

receive: function(e, ui) { 
    var drag_id = ui.draggable.attr("id");
    alert('draggable id: ' + drag_id);
}

Need Your Help

Multisite support for ActionMailer

ruby-on-rails ruby actionmailer

There exists the multisite plugin (http://github.com/dasil003/rails-multisite/tree/master) that allows for multiple view folders based on different sites. It especially allows you to only overwrite

Printing data from list of lists

c# list

I have a list in my program declared with

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.