Append child can`t add more than 1 child node

littleMario
var data={
    1:"dasf",
    2:"jlla",
    3:"jalf"
};
(function () {
    var table=document.createElement("table");
    var tr=document.createElement("tr");
    for(var i in data){
        tr.innerText=data[i];
        (function(){
             table.appendChild(tr);
              console.log("in"+tr.innerText)
         })();
        console.log("out"+table);
    }
})();

it always shows different and changes everytime,guessing the time appendchild happenes is not simply following?

Quentin

You only create one tr element.

Each time you append it, you move it from where it was in the DOM and put it in the new location.

If you want to create a new table row for each item in data, then you need to move your createElement call inside the loop.

(You also need to change how you are adding content to it, a tr element isn't allowed to contain text directly, and if you aren't putting multiple data cells in each row, you should probably be using a list instead of a table in the first place).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

If tbody has more than one child, add show element1

From Dev

How to add CSS if element has more than one child?

From Dev

The SOAPBody content cannot be extracted if more than 1 child element exists

From Dev

get count of families that have more than 1 child in their record

From Dev

Can't add more than 1 object to MongoDB collection

From Dev

Can't append child to clicked element

From Dev

jQuery stopPropagation() on more than one child object

From Dev

C++ pugiXML, Append a child before the first child in a node

From Dev

Add child node at the beginning of XML

From Dev

Powershell: add child node to XML

From Dev

JSTree, Add child node is not working

From Dev

Powershell: add child node in XML

From Dev

JSTree, Add child node is not working

From Dev

How to append child in the div parent node?

From Dev

jQuery to PHP: Add a selector class to parent element if more than 2 child elements

From Dev

Add common properties of the child objects and append it with Parent Key (Node.js)

From Dev

How can i add the strings to child nodes inside a node?

From Dev

check if list item has more than 1 direct span child in jquery

From Dev

child node locate lower than where it should be

From Dev

Child node is repeating, can't get it to work

From Dev

Can I add more than 1 millions strings in List?

From Dev

How to Append a child to the outerHTML of the father element rather than inside?

From Dev

Can't append a child to page from a chrome extension

From Dev

Why i couldn't append a child node to the document object model directly?

From Dev

Append child can not work in two circle

From Dev

Why isn't jQuery append method working when passing parent class to add a child input?

From Dev

how to add xml child node with namespace in python?

From Dev

Not able to add value of the matrix to the child of the node three

From Dev

How to add attribute for child node in XSL?

Related Related

  1. 1

    If tbody has more than one child, add show element1

  2. 2

    How to add CSS if element has more than one child?

  3. 3

    The SOAPBody content cannot be extracted if more than 1 child element exists

  4. 4

    get count of families that have more than 1 child in their record

  5. 5

    Can't add more than 1 object to MongoDB collection

  6. 6

    Can't append child to clicked element

  7. 7

    jQuery stopPropagation() on more than one child object

  8. 8

    C++ pugiXML, Append a child before the first child in a node

  9. 9

    Add child node at the beginning of XML

  10. 10

    Powershell: add child node to XML

  11. 11

    JSTree, Add child node is not working

  12. 12

    Powershell: add child node in XML

  13. 13

    JSTree, Add child node is not working

  14. 14

    How to append child in the div parent node?

  15. 15

    jQuery to PHP: Add a selector class to parent element if more than 2 child elements

  16. 16

    Add common properties of the child objects and append it with Parent Key (Node.js)

  17. 17

    How can i add the strings to child nodes inside a node?

  18. 18

    check if list item has more than 1 direct span child in jquery

  19. 19

    child node locate lower than where it should be

  20. 20

    Child node is repeating, can't get it to work

  21. 21

    Can I add more than 1 millions strings in List?

  22. 22

    How to Append a child to the outerHTML of the father element rather than inside?

  23. 23

    Can't append a child to page from a chrome extension

  24. 24

    Why i couldn't append a child node to the document object model directly?

  25. 25

    Append child can not work in two circle

  26. 26

    Why isn't jQuery append method working when passing parent class to add a child input?

  27. 27

    how to add xml child node with namespace in python?

  28. 28

    Not able to add value of the matrix to the child of the node three

  29. 29

    How to add attribute for child node in XSL?

HotTag

Archive