How to close and just add HTML element in D3.JS?
1 answer
The append method returns a new selection containing the added items ( See documentation ). So follow your code:
d3.select("#commiterStatsContainer") // initial selection
.append("div").attr("class", "chip") // new selection with a div
.append("img").attr("src", committers[i].avatar) // new selection of img in that div
.text(committers[i].login); // text for the img tag in the div.
Try this instead:
var div = d3.select("#commiterStatsContainer")
.append("div").attr("...");
div.append("img").attr("....");
div.append("p").html("....");
The variable div
is the selection of the newly created div, then you can use div.append()
to add new elements to that div.
+2
source to share