Is it possible to Clone HTML Elements in jQuery with new ID and Name?

后端 未结 4 1589
日久生厌
日久生厌 2020-12-11 01:42

I want to clone one row of a table, but when I clone, the new element\'s name and id will be the same as the element from which it was cloned.

4条回答
  •  猫巷女王i
    2020-12-11 02:16

    You can do something like:

    var x = $("#selector").clone();
    
    x.find('#oldID1').attr({id: "newID1", name: "newName1"});
    x.find('#oldID2').attr({id: "newID2", name: "newName2"});
    ...
    

    Once its done, you can append x to wherever you want.

    Pls note that the #selector above refers to your table row element.

提交回复
热议问题