I would add a rect
on every first child of a node list.
I loop this list and add a rectangle every time
What is happening is that the rect is getting added only on the last element of the loop.
let rect : NodeList = this.synoptic.nativeElement.querySelectorAll("#stops g");
let rect2 = document.createElementNS('http://www.w3.org/2000/svg','rect');
rect2.setAttribute("fill","red");
rect2.setAttribute('x', '0');
rect2.setAttribute('y', '0');
rect2.setAttribute('height', '50');
rect2.setAttribute('width', '50');
rect.forEach((elm : Node) => {
elm.insertBefore(rect2,elm.firstChild);
console.log(elm)
})
Here an example