How to select multiple selectors with selectAll?
Asked Answered
D

1

41

Is it possible to select multiple selectors in D3 using selectAll?

I want something like svg.selectAll("class1", "circle", "id2") to select all circle elements, class1 elements and id2 elements.

Is this possible?

Deadbeat answered 29/3, 2013 at 11:56 Comment(0)
N
67

Yes, you simply put the commas inside the selector string rather than passing separate strings:

svg.selectAll(".class1, circle, #id2")

I am assuming that "class1" is a css class, "circle" is a tag name, and "id2" is an ID attribute value.

Numerous answered 29/3, 2013 at 14:38 Comment(1)
Do d3's docs explain why a different syntax from CSS selector syntax was chosen?Timbered

© 2022 - 2024 — McMap. All rights reserved.