Something to keep in mind, in order to use yourVar.forEach() yourVar MUST be an array.
Also, when you chain properties you risk getting an ‘undefined’ value, especially if a query returns no results ( for example, if your list contained 0 LIs). In your specific case, listToWorkOn doesnt have the property listElements, so thats your error ![]()
Finally, the beauty of query selector all is that you can get a COLLECTION of elements via a CSS selector; but this means you must write your selector as specifically as possible, or you risk getting items outside your intended scope. As other people have pointed out you could use a more specific selector with document.querySelectorAll() such as “.special>li”
Iin case you are actually targeting a specific instance of .special, you can also do: listElements = listToWorkOn.querySelectorAll("li"). Assuming, you don’t have nested list inside your .special. I think this is what you were originally trying to do and I find this handy, when you want to do a .querySelectorAll() dynamically.
Hope this clears things up for you.