最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jquery ui droppable on parent child issue - Stack Overflow

programmeradmin13浏览0评论

I am using jquery ui droppable widget. I have the following structure :

Example Fiddle

 <div class="parent">
    parent
   <div class="child">
     child
   </div>
  </div>

Both parent and child elements are droppable and both are accepting the same item. My issue is when i am dropping the element on child than also parent drop event is executing ( please check the fiddle ). How can i stop this behaviour ?

I am using jquery ui droppable widget. I have the following structure :

Example Fiddle

 <div class="parent">
    parent
   <div class="child">
     child
   </div>
  </div>

Both parent and child elements are droppable and both are accepting the same item. My issue is when i am dropping the element on child than also parent drop event is executing ( please check the fiddle ). How can i stop this behaviour ?

Share Improve this question asked Mar 9, 2013 at 6:52 user1740381user1740381 2,1999 gold badges40 silver badges62 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

I guess the better way is to use greedy option of droppable. Don't forget to go through the API if you find any problem. http://api.jqueryui./droppable/#option-greedy

Here is how your code looks like with greedy option

$(".child").droppable({ 
    accept: '.item',
    greedy: true,
    drop: function(e, ui){ 
     alert("drop on child");
    }
});

There you go... !!!

发布评论

评论列表(0)

  1. 暂无评论