jQuery clone duplicate IDs

后端 未结 9 1865
醉梦人生
醉梦人生 2020-12-04 19:03

I have an HTML element with a large collection of unordered lists contained within it. I need to clone this element to place elsewhere on the page with different styles adde

9条回答
  •  死守一世寂寞
    2020-12-04 19:31

    Here is a solution with id.

    var clone = $("#MainConfig").clone();
    clone.find('[id]').each(function () { this.id = 'new_'+this.id });
    $('#smallConfig').append(clone);
    

    if you want dynamically set id, you can use counter instead of 'new_'.

提交回复
热议问题