How do you access/iterate through the child elements of a group in SVG.js

1k Views Asked by At

I'm using the SVG.js library, I have a group created with the draw.group() function and I'd like to apply attributes to every element in the group. I've tried accessing the group.children and group.childNodes directly, tried using a group.forEach(function(){}); loop. Can't figure it out and couldn't find anything in the docs.

On that note, I find the docs somewhat lacking and certainly in no danger of verbosity...

1

There are 1 best solutions below

0
On BEST ANSWER

I eventually found the group.children() method in the docs which will return an iterable array of the group's children.

Attributes may be applied to each child element using a loop, for example:

for (const child of myGroup.children()) {
  child.attr({
    fill: "#000000"
  });
}