d3.js Playing with Selections II (flat vs. hierarchy)

Based on the previews experiments you will get a flat array with all selected elements.

d3.selectAll("tbody td");

Selection

Using a chained (nested) selection

d3.selectAll("tbody tr").selectAll("td");

we get matrix of cells

Nested Selection

Now we are in full control and can manipulate eg. the color of specific cells and rows

var td = d3.selectAll("tbody tr").selectAll("td");
td.style("color", function(d, i, j) { return (j<2 && i<2) ? null : "red"; });

Nested Selection

Leave a comment