views:

67

answers:

1

i am new to using jQuery and I just want to know how I can check whether a draggable object has been removed from the droppable object.

Example, i have a dog and I dragged it to a doghouse which has a lightbulb that will light up indicating that the dog is there. When i drag the dog out of the doghouse, the lightbulb should go off again indicating the dog's absence.

Help me please coz I really don't have any idea how to do this. Thanks in advance. :)

A: 

You could use the the [drop event][1] embedded in UI / draggable. Here's some example code:

$("#doghouse").droppable(
    {drop:function(event,ui){
        if (ui.draggable[0].id=="dog"){
            //show lightbulb
        }
    });
Adrian Grigore
thanks for the immediate response. i'm sorry but i didn't quite get that. i'm really new to using jQuery like 1 day old. Can you point me to some examples or just a short code so that i'll have something to ponder on? Thanks a lot.
Kim
Please see my edit above.
Adrian Grigore
now i get what you were saying but, with all due respect, i don't think this is exactly what i needed. this only covers up the dragging part. but what i wanted to do is to check if a draggable item (dog) has been removed from a droppable item (doghouse) which will make the light go out. not just the dragging part. thanks for helping me out.
Kim
http://docs.jquery.com/UI/Droppable#event-out i think this is what i needed but i don't quite know how to use this. :(
Kim
You are right, the drop event works even better. See my edit above.
Adrian Grigore
Ive also added an example to get you started.
Adrian Grigore
thanks a lot for this.. ;)
Kim