D3当ID中有一个点时,如何通过ID选择元素

Ben*_*nas 3 javascript select d3.js

我有

<text id="element.id.with.dots" x="10" xml:space="preserve" y="10" stroke="none">
Run Code Online (Sandbox Code Playgroud)

如何使用d3.select选择它?这似乎不起作用,它返回null

var textElem = d3.select("text[id=element\\.id\\.with\\.dots]");
Run Code Online (Sandbox Code Playgroud)

还有这个 :

var textElem = d3.select("text[id=element.id.with.dots]");
Run Code Online (Sandbox Code Playgroud)

在Firebug控制台窗口中给出错误:

SyntaxError: An invalid or illegal string was specified
Run Code Online (Sandbox Code Playgroud)

nik*_*shr 9

使用带引号的字符串来分隔属性的值:

var textElem = d3.select("text[id='element.id.with.dots']");
Run Code Online (Sandbox Code Playgroud)

var el = d3.select("text[id='element.id.with.dots']");
el.style({fill: 'red'})
Run Code Online (Sandbox Code Playgroud)
<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>
Run Code Online (Sandbox Code Playgroud)