About
D3 adopts the W3C Selectors API to identify document elements for selection.
Any number of operators can be applied to selected elements. These operators wrap the W3C DOM API, setting:
- attributes (attr),
- styles (style),
- properties (property),
- HTML (html)
- and text (text) content.
D3’s selection operators such as attr, style and property allow to specify the value either as:
- a constant (the same for all selected elements)
- or a function (computed separately for each element).
Since each selection is simply an array, elements can also be accessed directly (e.g., [0]).
If you’re using a DOM framework like React, you probably don’t need selections (if you don’t need transitions)
Articles Related
Nested / Hierarchy Selection
Operations
- .each allows a function to be called on each element of a selection
- .call allows a function to be called on the selection itself.