Latest Lists

How to enumerate (an updated) HTML list elements in DIV using javascript?

Hi I have a list elements inside a div. I have javascript function to dynamically add list elements to the div using (appendChild). I have another javascript function to enumerate the list items. Now. For the list items that originally exists in the page, enumerate function work. But when I start to add list elements dynamically, they do not get enumerated. I also noticed that when I view the page source, the newely added elements are not shown. Can somebody help me with a way to keep track of the updated list elements? function Enumerate() { var mylist = document.getElementById('firstlist'); for (i=0; i<mylist.childNodes.length; i++){ if (mylist.childNodes[i].nodeName=="LI") alert(mylist.childNodes[i].innerHTML); } }

Public Comments

  1. Edit your code to include some spaces so we can read it in its entirety.
  2. a couple of things 1) if you use firefox, and select the added items on the page, then right click you can see whats going on with the dynamic elements. they never show in a simple view source. 2) it depends where you dynamically added them! If the code doesn't get them, they may not have been legitimate children!
Powered by Yahoo! Answers