问题
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