You're almost there -- d
is a D3 selection, so you cannot compare elements to it directly. Rather, you need to extract the elements in the selection and then check whether .source
or .target
is in this array:
var e = [];
d.each(function(a, i) { e[i] = a; });
link.style("stroke-opacity", function(o) {
return e.indexOf(o.source) != -1 || e.indexOf(o.target) != -1 ? 1 : opacity;
})
.style("stroke", function(o) {
return e.indexOf(o.source) != -1 || e.indexOf(o.target) != -1 ? color : "#000" ;
});
Complete example here.