我有SVG爲:D3添加多類使用功能
<g class="user" title="Michael" rel="tooltip" transform = "rotate(-12.364052661705784)translate(360)" style="fill: #9467bd; "></g>
我想添加一個類一樣稱號。我試過
d3.selectAll('.user').attr('class','Michael');
但它取代了原來的類。然後我試了
d3.selectAll('.user').classed('Michael',true);
它的工作原理!但現在我想返回類名稱與功能如
d3.selectAll('.user').classed(function(){return this.attr('title');},true);
它不起作用。我怎樣才能做到這一點?
感謝
順便說一句,你也可以用'.classed('user Michael',true)'指定多個類:https://github.com/mbostock/d3/wiki/Selections – Milimetric