How to access the parentNode of a d3.js selection?

前端 未结 4 1244
情歌与酒
情歌与酒 2020-12-05 06:46

I\'ve created the following document:


    ​
    <         


        
4条回答
  •  隐瞒了意图╮
    2020-12-05 06:55

    There are two ways to access it.
    Either use the third variable like this: someNode.attr("someAttrib", function(d, i, j) { console.log(d, i, j); });. The j contains the data you supplied to the parent node.
    or use d3.select(this.parentNode).data()[0].id;.

    An example:

    
    
    
    
    

提交回复
热议问题