views:

15

answers:

0

I would like to check to see if an item with id === itemId is dropped on a droppable element, using native Drag and Drop.

function dragDrop(itemId){        

    var droppable = document.querySelector('#droppableElement');

    addEvent(droppable, 'drop', function(e){
        if (e.preventDefault){
            e.preventDefault();
        }
        // How do I check that the id of the dropped item === itemId    
        if (e.dataTransfer.getData('id') === itemId){ 
            alert('Successfuly dropped item with id = ' itemId + '.');
        }
    });
}

draggableItem = document.querySelector('#draggable');
dragDrop(draggableItem);

The comment is where I need help. This link was my point of departure. http://html5doctor.com/native-drag-and-drop