Select element with double dot in id, error: “#octo:cat” is not a valid selector

女生的网名这么多〃 提交于 2019-12-11 07:27:13

问题


Given an svg with an existing id="kvg:StrokeNumbers_07425",

<g id="kvg:StrokeNumbers_07425" style="font-size:8;fill:blue;">...</g>

I do the following :

d3.select("#kvg:StrokeNumbers_07425").attr("style","fill:red;");

and get the following error message :

Uncaught SyntaxError: Failed to execute 'querySelector' on 'Document': 
'#kvg:StrokeNumbers_07425' is not a valid selector.

It's likely due to the :.

What should I do to make it work?


EDIT: http://jsfiddle.net/0v7jjpdd/1/


回答1:


Escape the : as such

d3.select("#kvg\\:StrokeNumbers_07425").attr("style","fill:red;");

JSFiddle Link



来源:https://stackoverflow.com/questions/28287929/select-element-with-double-dot-in-id-error-octocat-is-not-a-valid-selector

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