score:3

Accepted answer

The most obvious solution is to use selection.filter() to get a subset of the selection containing all the nodes for which the filter is true. You can then use .attr() on the selection returned by .filter() to apply changes to the attribute values of the new subset only.

function selectNodesWithProperty(container, key, value){
  d3.selectAll(container)
    .filter(d => value === d[key]) 
    .attr('fill', 'red') 
}

Related Query

More Query from same tag