Clone
and change id

前端 未结 4 1924
伪装坚强ぢ
伪装坚强ぢ 2020-12-01 06:30

How can I using javascript make clone of some

and set his id different from original. Jquery also will be nice.

4条回答
  •  [愿得一人]
    2020-12-01 06:55

    var div = document.getElementById('div_id'),
        clone = div.cloneNode(true); // true means clone all childNodes and all event handlers
    clone.id = "some_id";
    document.body.appendChild(clone);
    

提交回复
热议问题