A
A
Andrew2018-02-07 21:08:17
JavaScript
Andrew, 2018-02-07 21:08:17

How to clone nodes in a loop with content replacement in js?

Do not tell me what is my mistake?
There is an array with data that needs to be displayed on the screen. I clone the element, after I add the content to its fields, and only one is displayed.
I assume that the error is in the output, but I do not understand how it is correct?

wraper[wraper.length - 1].parentNode.insertBefore(clon, wraper[wraper.length - 1].nextSibling);

All code https://jsfiddle.net/kurhinsan/he5ddn5y/
for (var i = 0; i < row.length; i++) {
    clon.children[0].innerHTML = row[i].split(';')[0];
    clon.children[1].innerHTML = row[i].split(';')[1];

    console.log(clon.children[0].innerHTML);

    wraper[wraper.length - 1].parentNode.insertBefore(clon, wraper[wraper.length - 1].nextSibling);
  }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anatoly Zharov, 2018-02-07
@Kaspel

on the fiddle I see return in the loop, it returns from the function immediately on the first iteration of the loop

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question