QueueHammer QueueHammer - 1 year ago 136
Javascript Question

A d3.select... equivalent to jQuery.children()

I'm using d3 to append some elements on enter() and then update them later. However, the next time i try to select those elements the selection is much larger than the original. This is because the original selection elements now have children that are the same type e.g.;

. I expected selectAll() to only work at the first decedent level like jQuery.children() is there an equivalent in d3? If not whats the most efficient way to shim that?

Answer Source

There's no equivalent to jQuery.children(). This is usually handled by assigning a distinguishing class to the elements you want to select together, e.g. something like this.

   .attr("class", "parent")
   .attr("class", "child");

svg.selectAll("g"); // all g elements
svg.selectAll("g.parent"); // only parents
svg.selectAll("g.child"); // only children
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download