I have a collection of SVG groups g1
, g2
, ..., gn
, each having m paths as children. The paths in each group have distinct classes "C1"
, "C2"
, ..., "Cm"
. Only these paths have these classes. Therefore, a selection such as d3.selectAll(".C1")
(or, alternatively, $(".C1")
) will consist of exactly n paths, one from each of the groups g1
,...,gn
.
The paths in each group can overlap visually, but there is no overlap between paths in different groups.
Initially all the paths are colored black, and I would like to implement the ability to highlight (with a different color) all the paths belonging to a particular class.
An expression like
d3.selectAll("." + cx).attr("style", "stroke: #0f0")
or
$("." + cx).attr("style", "stroke: #0f0")
will set to green (#0f0) the color of all the paths having class cx
(where cx
holds one of the strings "C1"
, ..., "Cm"
), but unfortunately it often fails to produce the desired highlighting effect, namely, when the selected paths are visually obscured by the other paths. (IOW, these not-highlighted paths get to be drawn "on top" of the highlighted ones, thereby obscuring the latter, at least partially.)
One solution would be to, before changing their color, first re-insert the selected paths into the DOM so that they are the last ones among their (by-design-unselected) siblings.
Of course, one could imagine writing some elaborate DOM-manipulation code to achieve this, but it occurs to me that this is precisely the type of code that d3
and jQuery
are meant to make unnecessary.
What would be the right incantation for doing this? And also, would there be any reason to prefer one of d3
or jQuery
for this task?