The comments below the question have all the information to fix the problem. However, for future readers, I'd like to write some points here.
First of all: always read the documentation. With few exceptions, it has all information you need. For instance, let's see what it says about select:
Selects the first element that matches the specified selector string. (emphases mine)
Now let's see your code:
d3.select('#id1','#id2')
// ^--------- two strings, separated by a comma
That's not a string. This is a string:
d3.select('#id1, #id2')
// ^--------- just one string here!
Second problem: select
selects the first element that matches the string. So, you want selectAll
, not select
.
Solution: it has to be:
d3.selectAll("#id1, #id")
Here is a demo, click the button:
d3.select("button").on("click", function() {
d3.selectAll("#c2, #c5").attr("fill", "brown");
})
<script src="https://d3js.org/d3.v4.min.js"></script>
<button>Click me</button>
<svg>
<circle id="c1" cx="20" cy="30" r="10" fill="teal"></circle>
<circle id="c2" cx="60" cy="30" r="10" fill="teal"></circle>
<circle id="c3" cx="100" cy="30" r="10" fill="teal"></circle>
<circle id="c4" cx="140" cy="30" r="10" fill="teal"></circle>
<circle id="c5" cx="180" cy="30" r="10" fill="teal"></circle>
</svg>