Cannot select SVG foreignObject element in d3

杀马特。学长 韩版系。学妹 提交于 2019-12-03 12:00:52

Strictly speaking, SVG is case sensitive so you should use <foreignObject> instead of <foreignobject>.

More seriously though, is that there's an open bug in WebKit that prevents camelCase elements from being selected.

One possible workaround is to use:

.selectAll(function() { return this.getElementsByTagName("foreignObject"); })

(This may not work in older WebKit versions though; see the now-closed WebKit bug 46800.)

Alternatively, you can use CSS classes or IDs and select your elements that way instead. I would recommend this approach at the moment if possible, given the various aforementioned bugs.

You should be able to d3.selectAll("foreignObject") or svg.selectAll("foreignObject"). It may be that extra comma in your foreignObject attributes (between x and y). I've only inserted foreignObject elements using D3, so perhaps there's something about embedding them like this that's different.

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