What the What’s a NodeList!?
If you’re wondering what a NodeList is, you’re probably - like me - learning how to do fun stuff on the front-end. I’m not an expert on this, but I just had an “ah-ha!” moment I’d like to share. The NodeList is not something you can easily construct yourself. You have to use javascript to pull it out of the DOM. I’m guessing that technically, if you really know what you’re doing you could. But if you’re reading this now just accept the over-simplification for the moment.
With an array you can build your own with something like:
`var myArray = [1, "b", varName]`
I was completely unable to find a way to declare a NodeList like that. Instead, you have to use a JavaScript method to pull a nodelist out of the DOM. The [two methods Mozilla suggests](https://developer.mozilla.org/en-US/docs/Web/API/NodeList "Mozilla") are `Node.childNodes` and `document.querySelectorAll`. I'll assume you don't know what those two methods are. Don't worry. I didn't either ten minutes ago. What those are, in my words, are ways to get yourself a NodeList. The code would look a little something like this:
`var myNodeList = document.querySelectorAll("div.importantClass")`
So breaking that down... we're taking setting a new variable equal to something -- `var myNodeList =`. That something is being pulled out of the `document` -- which is basically the page you're working on -- with the `.querySelectorAll` method -- which is going to look for anything that matchest the CSS selector: `("div.importantClass")`. Then, the client is going to give you a list of nodes (elements that [potentially] have parents and children) as an object of the type NodeList.
I think [querySelectorAll](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll) is the right place to start building NodeList objects. I hope this helps somebody. If you're reading this and see errors or can make clarifications, do let me know! :)











