First you need to create a (empty) selection of elements li:
d3.select(".ul_class")
.selectAll('li')
.data([4, 8, 15]).enter().append("li").text("hello");
You then associate the data with this empty selection, which will generate placeholders in the selection for the new data.
So you basically say:
"Select all the elements liand bind data to them [4, 8, 15]. For all data elements that are not yet bound, create a new element li."
Demo
source
share