Dominik Grzelak blog

D3 enter update multiple nodes with same data

[09.12.2016]
The key is the key:

var s = div.selectAll("div.enter").size();
var oneDiv = div.selectAll("div.update").data(data, function (d, i) {
return "key_" + (i + s + 1);
});
oneDiv.attr("class", "update");

var update = oneDiv.enter().append("div").attr("class", "enter");
update.html(function (d) {
return d;
});
oneDiv.exit().remove();