score:0

Accepted answer

the best way would probably be to add this class info when you create your <rects>. But if for whatever reason your setup doesn't allow you to, then you should have an array with the same number of elements as the number of <rects> that you have. .data() acts on all elements in an array, and each of those <rects> (in your case) inherits the information contained within each of the elements in the array: https://github.com/mbostock/d3/wiki/Selections#Data

Right now, when you execute your second code block, you are only updating to 2 <rects> because your array only contains 2 objects. What you could do then is create another array that has the total 100 elements, each with the class that you want :)

Let me know if you have any other questions!


Related Query

More Query from same tag