appendChild in for loop only adds 1 child

后端 未结 3 411
轻奢々
轻奢々 2021-01-05 10:38

In JavaScript I am creating a grid (the type of grid you see in Photoshop) with HTML tables. The grid size is going to be variable, i.e., changeable by the user, so the size

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-05 11:09

    If you want to make one copy of the element, you will need to clone it. Use cloneNode()

    So change

    grid.tr.appendChild(grid.td);
    

    to

    grid.tr.appendChild(grid.td.cloneNode(true));
    

提交回复
热议问题