Clone a div and change the ID's of it and all it's children to be unique

后端 未结 3 1948
遇见更好的自我
遇见更好的自我 2020-12-10 11:09

Using JQuery it possible to clone a Div like this and change add a new identifier to it\'s ID and all it\'s children ID\'s?

For instance I\'d like to be able to clon

3条回答
  •  北荒
    北荒 (楼主)
    2020-12-10 11:33

    $("#current_users").clone(false).find("*[id]").andSelf().each(function() { $(this).attr("id", $(this).attr("id") + "_cloned"); });
    

    And watch your events if there are any attached. You'll have to fix them up if they rely on ids.

提交回复
热议问题