This line overrides the attached eventlistener:
li_element.innerHTML += tdArray[i];
Setting innerHTML
replaces all the original elements within li_element
. +=
is just a shortcut to li_element.innerHTML = li_element.innerHTML + tdArray[i];
If tdArray[i]
contains just some text, you can add its content like this:
li_element.appendChild(document.createTextNode(tdArray[i]));
If tdArray[i]
contains elements, you could append a wrapper element, and then set the innerHTML
of the wrapper.