Accepted answer

Update: As per comment by Lars, one can read parent object's ID using'id') as well.

You cannot access the data for the parent element directly in an accessor function in d3.

The way to solve it would be to introduce in the data for the children a field which contains the parent_id. For your data structure, it would involve something like this:

Data.transcripts.responses.forEach(function (childArray, parent_idx) {
    childArray.forEach(function (d) { d.parent_id = parent_idx; });

Then using it while setting the id of the children: .attr('id', function (d, i) { return 'tl-' + d.parent_id + '-word-' + i; }).

Related Query

More Query from same tag