views:

35

answers:

1

I am currently playing around with jqueries drag and drop, basically I currently have a div (.drag_check) that holds a checkbox, I have the drag and drop working but I want to alert out the checkbox's ID once the element is dropped, I assume I have to use child but all my attempts have returned 'undefined'. Below is my code,

$('.drag_check').draggable({
    containment: 'document', 
    opacity:0.6, 
    revert: 'invalid',
    helper: 'clone',
    zIndex: 100
});

$("ul.searchPage").droppable({
    drop:
        function(e, ui) {
            var param = $(ui.draggable).attr('class')
            addlist(param)
            alert(param)
        }
})
A: 

You code seems alright, just a couple of suggestions:

  1. Add semicolons at the end of your lines (To avoid any issues).
  2. No need for a $(ui.draggable) since ui.draggable is already a jQuery object.

.

$("ul.searchPage").droppable({
   drop: function(event, ui){
      var param = ui.draggable.attr('class');
      addlist(param);
      alert(param);
   }
});

BTW= jQuery UI will add a couple of classes to the Draggable object, so you should consider that in your addlist function.

UberNeet