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?

J0e3gan
  • 8,740
  • 10
  • 53
  • 80
vibekeNYG
  • 471
  • 1
  • 5
  • 13

1 Answers1

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.

explunit
  • 18,967
  • 6
  • 69
  • 94