JackBurton
JackBurton

Reputation: 191

jQuery droppable not working

I'm trying to implement what I thought was a simple droppable in jQuery. I need the draggable items to have a numeric id that changes. The items are draggable but when I drag them to the drop target the alert doesn't fire. My code is as follows:

    <script>
    $(function() {
        $( ".draggable" ).draggable();
        $( ".trash" ).droppable({
            accept: ".draggable",
            drop: function( event, ui ) {
                alert('dropped');
            }
        });
    });
    </script>


<div id="5" class="draggable"><p>Drag to target</p></div>

<div id="trash"><p>Drop here</p></div>

Upvotes: 0

Views: 256

Answers (1)

Tuan
Tuan

Reputation: 5412

The droppable's selector should be #trash, referrring to the div's id and not its class attribute.

$("#trash").droppable ...

Upvotes: 2

Related Questions