score:11

Accepted answer

Use a quoted string to delimit the value of your attribute:

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>

score:0

Another solution would be to escape each period by putting a backslash \ before it—then you can use d3.select() or d3.selectAll() as usual.

You can use .replace(/\./g, '\\.') to add the backslashes automatically.

Remember (thanks, altocumulus!), to escape the backslashes themselves with another backslash if you're editing the id manually.

d3.select("#element\\.id\\.with\\.dots")


Related Query

More Query from same tag