Hello I am running this test:
var myList = document.getElementById('mainList');
var myListI = myList.getElementsByTagName('li');
var myLLength = myListI.length;
for (i=0;i<myLLength;i++) {
if (myListI[i].nextSibling)
alert(myListI[i].id+' is before '+myListI[i].nextSibling.id);
else
alert(myListI[i].id+' is last');
}
It prints:
li0 is before li1
li1 is before undefined
li2 is before li3
li3 is last
li0 and li1 were both on the page onload. li2 and li3 were added later dynamically. For some reason the dynamically added ones can't detect the "static" ones and visa versa.