Reinitialize jQuery UI droppable after adding elements

江枫思渺然 提交于 2020-01-05 02:50:19

问题


I have some elements that on page load are droppable. At some points I add some more of these elements (same selector) and I want the new elements to be droppable as well. Is the only option to call the original droppable function with all the options? You see, The droppable function call is pretty big, and I don't really want to duplicate code this way. Is there a more elegant way?

this is the code for clarification:

$('td:not(.td-disabled)').droppable({
        hoverClass: "ui-state-active",
        drop: function( event, ui ) {
            // ... very big block of code 
        }
    });
$('.td-disabled').removeClass('td-disabled');

// I dont want to do this:
$('td').droppable({
            hoverClass: "ui-state-active",
            drop: function( event, ui ) {
                // ... very big block of code 
            }
        });

回答1:


You can try:

var hoverCls = 'ui-state-active';
var dropFn = function(event, ui) {

};

$('td').droppable('destroy').droppable({
   hoverClass: hoverCls,
   drop: dropFn
});


来源:https://stackoverflow.com/questions/15315422/reinitialize-jquery-ui-droppable-after-adding-elements

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