Looping through LI elements in UL

getElementsByTagName() returns a NodeList, which can be used similar to an array, i.e., with bracket notation. Each element in the NodeList will represent a <ul> element.

If you want to access the list items, rather than the list, you should use getElementsByTagName("li").

For instance, if you have markup like this,

<ul id="foo">
  <li>First</li>
  <li>Second</li>
  <li>Third</li>
</ul>

you can access the list items this way,

var ul = document.getElementById("foo");
var items = ul.getElementsByTagName("li");
for (var i = 0; i < items.length; ++i) {
  // do something with items[i], which is a <li> element
}