jquery dynamic div addition with droppable attribute

陌路散爱 提交于 2019-12-11 07:25:17

问题


I am trying to build a layout page. this page has 1 main panel. if a user clicks "create new tab" I want to build a new div, and make that div droppable. In this watered down example. I want to click "Create new tab" and then be able to drop the "Other" div into it.

see my fiddle: Fiddle

  $('#newTab').click (function()
  {
    i++;
    var div = $('<div class="drop"/></div>').appendTo('#mainBucket');
    div.attr('id', 'holdy'+i);
    div.addClass('tabModule drop');
    div.html('hello');
  });

回答1:


You have to make every new div dropable on its own. After you created a new div you need to apply jQuerys dropable-method. Dropable is not applied to elements that are created in future and matching your selector before, so you have to do this on your own.

var newDiv = jQuery('<div class="drop" />').droppable().attachTo('body')

i modified your example here: http://jsfiddle.net/Valtos/dQzy5/7/



来源:https://stackoverflow.com/questions/21587961/jquery-dynamic-div-addition-with-droppable-attribute

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!