vibekeNYG
vibekeNYG

Reputation: 471

How to select multiple selectors with selectAll?

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?

Upvotes: 41

Views: 24084

Answers (1)

Steve P
Steve P

Reputation: 19397

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.

Upvotes: 67

Related Questions