开发者

Getting the id of child element based on the parents class name

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:

  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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜