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 o开发者_StackOverflownce 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)
}
})
You code seems alright, just a couple of suggestions:
- Add semicolons at the end of your lines (To avoid any issues).
- 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.
精彩评论