score:1

Accepted answer

You can iterate over a d3 selection and compare it's attributes as shown below.

d3.selectAll("svg").each(function() {
  var svg = d3.select(this);
  var id = svg.attr("id");
  var value = id == 'y' ? 0 : 1;
  console.log(" ID : "+id+", Value: "+value);
})
<script src="https://d3js.org/d3.v4.min.js"></script>
<svg id="x"></svg>
<svg id="y"></svg>
<svg id="z"></svg>


Related Query

More Query from same tag