Reputation: 6894
I have multiple droppable areas ..
for(j=0; j<2; j++) {
$('#dropElement' + j).droppable( {
drop : handleElementDrop
});
}
function handleElementDrop( event, ui ) {
}
How can I pass 'j' to event handleElementDrop so that i can know to which area the element was dropped to .. ?
Upvotes: 0
Views: 2871
Reputation: 66663
You can use jQuery's data() function to transport any data (not just integeres, even arrays or objects) within elements..
For ex:
for(j=0; j<2; j++) {
$('#dropElement' + j).data('mykey', myData); // set data
$('#dropElement' + j).droppable( {
drop : handleElementDrop
});
}
function handleElementDrop( event, ui ) {
var myData = $(this).data('mykey'); // get data
}
Upvotes: 1
Reputation: 6619
You can use this
inside the handleElementDrop to get the dropped. I should store the ID inside a data attribute. But however this will work for you:
for(j=0; j<2; j++) {
$('#dropElement' + j).droppable( {
drop : handleElementDrop
});
}
function handleElementDrop( event, ui ) {
alert(this."id".replace("dropElement",""))
}
Upvotes: 0
Reputation: 76870
I think you could do
drop: function(event, ui) {
alert(this.id);
}
to find the id
of the droppable (so you now which droppable has been used)
fiddle here http://jsfiddle.net/r5rzX/
Upvotes: 1