This question is on d3, v5.
I'm trying to attach the class of the parent element to the child as I create the child element.
var data = [
[0,10,20],
[10,20,30],
[45,55,65]
];
var svg = d3.select("svg");
var rowHeight = 15;
// dummy domain
var xScale = d3.scaleLinear().range([0,100]).domain([0,100]);
var rows = svg.selectAll("g")
.data(data)
.enter()
.append("g")
.attr("transform", (d,i)=>`translate(0,${rowHeight*i})`)
.attr("class", (d,i)=>"r"+i)
;
rows.selectAll("g")
.data((d)=>d)
.enter()
.append("g")
.attr("transform", (d,i)=>`translate(${xScale(d)})`)
.attr("class", (d,i)=>"c"+i) // how to get class = r* here?
// tried d3.select(this.parentNode).attr("class") but doesn't work
;
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/5.7.0/d3.min.js"></script>
<svg width=500 height=100></svg>
I tried d3.select(this.parentNode).attr("class")
but that's throwing an error.
The basic idea is to get the row and column classes into each of the "g" elements, so further selections will be easier.
Thank you!