小编use*_*621的帖子

如何获取svg元素类型

我有一个问题,我怎么能得到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()将返回选择的第一个元素

javascript svg d3.js

4
推荐指数
1
解决办法
6805
查看次数

标签 统计

d3.js ×1

javascript ×1

svg ×1