views:

28

answers:

2

Hi all,

how can i get the ID from the current Draggabe Item?

<style type="text/css">
    .red{ color: #ff0000; }    
</style>

<script type="text/javascript">
    $(function() {

    $(".dragg li").draggable();


    $("#droppable").droppable({

    hoverClass: 'red',
    over: function(event, ui)
    {
        //  $( --- ID FROM THE CURRENT DRAGABLE LI --- ).css('color','#ff0000');
    },
    out: function(event, ui)
    {
        // $( --- ID FROM THE CURRENT DRAGABLE LI --- ).css('color','#000000');
    }

    });


    });
</script>


    <div class="dragg">
        <li id="b1">Drag me to my target</li>
        <li id="b2">Drag me to my target</li>
        <li id="b3">Drag me to my target</li>        
    </div>

   <div id="droppable"  style="border: 1px solid #000000;">
       <br /><br />Drop here<br /><br />
   </div>

http://jsfiddle.net/FrbW8/13/

kind reagards peter

A: 
$('.dragg li').mouseup(function(){
    var draggedID = $(this).attr("id");
});

Should return your id.

Squirkle
Except that OP wants it triggered by droppable's `over` and `out` events. Otherwise, your answer is correct. :o)
patrick dw
+2  A: 

You can get the draggable through the passed in ui argument like so: ui.draggable.

over: function(event, ui)
{
    ui.draggable.css('color','#ff0000');
},
out: function(event, ui)
{
    ui.draggable.css('color','#000000');
}

Or, if you want the id: ui.draggable.attr("id");

stjowa