我有一个问题,我怎么能得到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);
}
Run Code Online (Sandbox Code Playgroud)
但它似乎没有用,有人可以帮忙,谢谢!
***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);
}
Run Code Online (Sandbox Code Playgroud)
cauz selection.node()将返回选择的第一个元素