user4973
user4973

Reputation: 85

JQuery multiple droppables and one function to handle each

Being new to JavaScript/JQuery I'm having a bit of a problem figuring out how could I implement registering drop function of multiple droppables to one function, for example:

$('#droppableLW').droppable({
    drop : handleUIDropEvent
});

$('#droppableRW').droppable({
    drop : handleUIDropEvent
});

And obtaining the id of droppable inside handleUIDropEvent method, for instance to achieve this:

function handleUIDropEvent(event, ui) {
   var droppableId = somehowGottaGetIt;
   if (new String(droppableId).valueOf() == new String("droppableLW").valueOf()) {
      ...
   } else {
      ...
   }

}

Upvotes: 0

Views: 37

Answers (1)

EduSanCon
EduSanCon

Reputation: 1929

To do that just use the class attribute instead the id

$('.droppableObject').droppable({
    drop : function( event, ui ) {
        if ( this.id == "something" ) {
            // do things
        }
    }
});

Upvotes: 1

Related Questions