Search code examples
jqueryjquery-uijquery-selectorsdraggablejquery-callback

jQuery UI get property of element in draggable div on drop:


$('#drop_area').droppable({
    accept: '.draggable',
    drop: on_element_drop
});

function on_element_drop(event, ui){

}

<div class="draggable">
    <img src="test.png" alt="3">
</div>

I'm trying to figure out how I can get the 'alt' property of the image in this draggable div from the 'ui' argument passed to 'on_element_drop.' Anyone know how to do this?

The closest I seem to get is:

ui.helper.context.children[0].attr('alt');

however this doesn't work.


Solution

  • ui.draggable.find("img").attr("alt")
    

    http://jsfiddle.net/3SfBJ/2