开发者

call method on dynamically added contents in jQuery

开发者 https://www.devze.com 2023-03-25 12:17 出处:网络
I have a list that call ListReorder() method from ListReorder Plugin on that it\'s work correctly but when add an item to list dynamically and recall ListReorder function on that list don\'t work on d

I have a list that call ListReorder() method from ListReorder Plugin on that it's work correctly but when add an item to list dynamically and recall ListReorder function on that list don't work on dynamically added list items:

function DragDropList(){        

var lists = $('ul#list1').ListReorder();

lists.bind('listorderchanged', function(evt, jqList, listOrder) {
var str="";
        for (var i = 0; i < listOrder.length; i++)
        {
            str += "<div class='gadget'>" + Gadgets[listOrder[i]] + "\n</div>";
        }
        $("#Preview").contents().find("开发者_C百科.sidebar").html(str);
});
}



 //add Gadget

$("#addGadgetBtn").live('click',function()
    {
        //add new list item here
        DragDropList();
    }


Probably, you need to use

lists.live();

instead of

lists.bind();


You need to make a change in the plugin and expose its resetList() method.

Change

function resetList() {

to

this.resetList = function() {

and then after you insert the new elements in the list run $('ul#list1').resetList()

0

精彩评论

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