Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

D3 how to select element by ID when there is a dot in ID

I have

<text id="element.id.with.dots" x="10" xml:space="preserve" y="10" stroke="none">

How can I select it using d3.select? This doesn't seem to work, it returns null

var textElem = d3.select("text[id=element\\.id\\.with\\.dots]");

and this :

var textElem = d3.select("text[id=element.id.with.dots]");

gives me error in Firebug console window:

SyntaxError: An invalid or illegal string was specified
like image 309
Benas Avatar asked Oct 14 '25 21:10

Benas


1 Answers

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>
like image 111
nikoshr Avatar answered Oct 17 '25 12:10

nikoshr