Add child to DOM table

I use a clone to dynamically add a new row to the DOM table from a button click event, as shown below. but I want to add the cloned node at a specific row position in the DOM table. I know that I can do this using the paste option, but I want to use this with cloning.

    var newNode = tblBody.rows[1].cloneNode(true); 
    tblBody.appendChild(newNode);

is there any way to insert or add "newNode" to position i, dynamically select, adding it as the last line.

+4
source share
2 answers

.insertBefore() tblBody newNode , tblBody, node .

    // put this node----v  before this----v
tblBody.insertBefore(newNode, tblBody.rows[i]);

tblBody.rows[i] null undefined, .insertBefore() .appendChild() .

+4

Source: https://habr.com/ru/post/1525617/


All Articles