D3访问html属性

问题描述 投票:0回答:1

我有以下代码遍历所有rect节点:

d3.selectAll("svg g rect")
            .on('mouseover', function (d) {
                console.log(this);
}); 

Console.log打印:

<rect class="cls" name="UK" style="fill: #fdb462;" transform="translate(52 50)" x="805.625" y="0" width="13.75" height="229.018" >...</rect>

如何访问rect标签的名称属性(值为“ UK”)?我尝试了this.name,但是它不起作用。

javascript d3.js
1个回答
0
投票

得到答案:

this.attributes["name"].value
© www.soinside.com 2019 - 2024. All rights reserved.