Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 921
vibekeNYG Avatar asked Mar 29 '13 11:03

vibekeNYG


People also ask

What do the select () and selectAll () functions in d3 do?

d3. select selects the first matching element whilst d3. selectAll selects all matching elements. Both functions take a string as its only argument.

How do you select multiple elements?

Selecting multiple elements Alternatively, hold down the Ctrl / Shift key on your keyboard (Cmd key for Mac) and click the elements to select them. Tip: You can select all elements at once by pressing Ctrl+A on your keyboard.


1 Answers

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.

like image 173
explunit Avatar answered Sep 16 '22 20:09

explunit