document.createTextNode not working :/

751 views Asked by At

So i am making this program where i need to create an ordered list with lots of list elements inside. This is the code:

for(i = 0; i < numbers.length; i++) {
  document.createElement("ls").appendChild(document.createTextNode(eval(numbers[i])));
  document.getElementById("list").appendChild(document.createElement("ls"));
}

It only creates the list elements, it doesn't put the text nodes anywhere in the html document. :/

Does anyone know why this happens and how to fix it? Would really help me out.

1

There are 1 answers

0
uri2x On

Instead of adding the "ls" element you've created on the first row to the "list" element, you're creating a new (empty) one and adding it.

Change it to:

  var ls = document.createElement("ls").appendChild(document.createTextNode(eval(numbers[i])));
  document.getElementById("list").appendChild(ls);