Really need help
i am using jquery sortable.
And i am looking to grab just the id from the list element that 开发者_如何学Cis being dragged.
"Not all off them"
Here is an example http://jsfiddle.net/isimpledesign/85LdV/1/
this alerts back an array but i need it to give me back just the id of the element that is being dragged so i can pass it to a php file.
Can someone please help me with this????
Just to clarify Chad's answer a bit -
$(function() {
$("#sortable").sortable({
update: function(event, ui) {
// i need to get the class text that is being dragged i.e
var order = $(this).sortable("serialize");
alert(order);
/*
No need to bind any other events, ui.item is the dragged
item in 'update' too and we only want to capture the id when the sort
has changed presumably
*/
alert(ui.item.attr('id'));
/*
No need for subscripting, ui.item is a jquery object so
we can just call attr() on it to get the ID
*/
}
});
});
Use the start
event:
$(function() {
$("#sortable").sortable({
update: function(event, ui) {
// i need to get the class text that is being dragged i.e
var order = $(this).sortable("serialize");
alert(order);
},
//Start event fires on the start of a sort
//you can store the id from in here
start: function(event, ui) {
//here ui.item contains a jquery object that is the item being dragged
alert(ui.item[0].id);
}
});
});
Use this:
$(function() {
var lastMoved = null;
$("#sortable li").mousedown(function(){
lastMoved = this;
});
$("#sortable").sortable({
update: function(event, ui) {
alert($(lastMoved).attr("id"));
}
});
});
It's tested and working. Hope this helps. Cheers.
精彩评论