質問があります。svg 要素のタイプを取得するにはどうすればよいですか。ところで、d3.js を使用しています。
私はこのようなものを持っています
var selectedElement = svg.select("." + STYLE.selected);
if (selectedElement instanceof SVGCircleElement){
alert("here circle");
selectedElement.style("fill", function(){return d3.rgb(d3.select(this).attr("fill"));});
}
if (selectedElement instanceof SVGPathElement){
alert("here path");
appendMarkerm(selectedElement,false);
}
しかし、それはうまくいかないようです、誰かがここで助けてくれます、ありがとう!!
***finally, i made it work like this***
var selectedElement = svg.select("." + STYLE.selected);
if (selectedElement.node() instanceof SVGCircleElement){
selectedElement.style("fill", function(){return d3.rgb(d3.select(this).attr("fill"));});
}
if (selectedElement.node() instanceof SVGPathElement){
changeMarkerStyle(selectedElement,false);
}
cauz selection.node() は選択の最初の要素を返します