I've the a node like:
<div>
<svg ...>
<g class="graph">
<path class="myarea" d="...AAA..." pos="p1"> </path>
</g>
<g class="graph">
<path class="myarea" d="...BBB..." pos="p2"> </path>
</g>
<g class="graph">
<path class="myarea" d="...CCC..." pos="p3"> </path>
</g>
/svg>
</div>
I am trying to select a specific node (e.g where d="...BBB...") which has the attribute pos='p2'
d3.selectAll(".myarea").each(function(d,i) {
console.log("-> ", d3.select(this).attr("pos"), d3.select(this).attr("pos") == 'p2' );
});
This produces/returns an arrays with all 3 entries:
-> p0 false
-> p1 true
-> p2 false
-> [Array(3)]
I am interested in selecting just one, in this case the one with .attr("pos") == 'p2'
so I'd like to return just one element.
I've tried with map()
and filter()
but without success.
What is the correct way to select a specific element based on an attribute value?