Detecting classname of SVGAnimatedString

。_饼干妹妹 提交于 2020-12-29 08:55:29

问题


I had a problem with a SVG map I was building, the functions triggered by onmouseover on g were not working. I used then

window.onmouseover=function(e) {
            console.log(e.target.className);
        };

to see if there was any problem with the classname, and then discovered than instead of the classname I was using, the system was detecting

SVGAnimatedString {animVal: "", baseVal: ""}

Something that never happened to me before the hundreds of times I've used similar code. Any idea how can I get the actual classname of the g elements on mouseover? Thanks


回答1:


Simplest way:

e.target.className.baseVal

Another way:

e.target.getAttribute("class")



回答2:


Make sure you also set the class name inside the svg path tags and then try e.target.getAttribute("class")

That worked for me.



来源:https://stackoverflow.com/questions/29454340/detecting-classname-of-svganimatedstring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!