Home
<!doctype html> <html> <head> <script src="https://d3js.org/d3.v4.min.js"></script> </head> <body> <script> var data = [4, 1, 6, 2, 8, 9]; var body = d3.select("body") .selectAll("span") .data(data) .enter().append("span") .style('color', function(d) { if (d % 2 === 0) { return "green"; } else { return "red"; } }) .text(function(d) { return d + " "; }); </script> </body> </html>
Result: