enter
:
-
Returns the enter selection: placeholder nodes for each datum that had no corresponding DOM element in the selection.
-
The enter selection is empty for selections not returned by selection.data.
-
The enter selection is typically used to create “missing” elements corresponding to new data.
-
For example, to create DIV elements from an array of numbers:
const div = d3.select("body")
.selectAll("div")
.data([4, 8, 15, 16, 23, 42])
.enter().append("div")
.text(d => d);
- If the body is initially empty, the above code will create six new DIV elements, append them to the body in-order, and assign their text content as the associated (string-coerced) number:
<div>4</div>
<div>8</div>
<div>15</div>
<div>16</div>
<div>23</div>
<div>42</div>
Click Fork
Button to Play with this on your own
Enter and Append with Existing Rects
Previous | Next |
---|---|
← Selections | SVG → |