A simple modification of your current code would work. Instead of using document.getElementsByTagName("li"), use shooping.getElementsByTagName("li"). The only time you need a for loop is if you want to loop through the array of returned list items. To find the number of list items, you only need the length property, as you've done.