我有
<text id="element.id.with.dots" x="10" xml:space="preserve" y="10" stroke="none">
如何使用 d3.select 选择它? 这似乎不起作用,它返回 null
var textElem = d3.select("text[id=element\\.id\\.with\\.dots]");
还有这个:
var textElem = d3.select("text[id=element.id.with.dots]");
在 Firebug 控制台窗口中给我错误:
SyntaxError: An invalid or illegal string was specified
最佳答案
使用带引号的字符串来分隔属性的值:
var textElem = d3.select("text[id='element.id.with.dots']");
var el = d3.select("text[id='element.id.with.dots']");
el.style({fill: 'red'})
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>
<svg>
<text id="element.id.with.dots" x="10" xml:space="preserve" y="10" stroke="none">Text/<text>
</svg>
关于javascript - D3 如何在ID中有点时按ID选择元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33502614/