//Array with 4 objects var dataArray = [ {value : 'one', color:'red', width: 100}, {value: 'two', color:'green', width: 200}, {value: 'three', color:'blue', width: 150}, {value: 'four', color:'yellow', width: 300} ]; function render(data) { //First use data function and pass data var updateDivSelection = d3.select('body').selectAll('div'). data(data); //But updateDivSelection will be empty //Use enter to append the divs var enterDivSelection = updateDivSelection.enter(). append('div'). text('div'); // Simply printing text 'div' in div } //Calling render function and passing the data render(dataArray);
<!-- no div elements initially --> <body> </body