d3.selectAll returns an empty array, but d3.select returns an element
I have elements with the class "state". When I use the code:
d3.selectAll(".state")
An empty array is returned, even though I've checked the page's DOM and there are several objects with "state" as their class. However, when I try it with d3.select, as so:
d3.select(".state")
An element is returned -- I'm at a bit of a loss here. I have tried using id's instead, but the behavior persisted. Surely I'm missing something?
It returns an element, but that element is null. So, the effect is the same. Read more about select vs. selectAll in How Selections Work.
Ah ha! So it does. Alright, time for some reading.
I just figured out exactly what was amiss. My data is loaded via JSON, but the selectAll functions in question were being called outside of the d3.json callback. Derr. Slowly but surely.