我有以下代码遍历所有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,但是它不起作用。
得到答案:
this.attributes["name"].value