I am writing you because I'm struggling with D3.js (D3-selection) for moving existing elements positions in the SVG.
I've seen a lot of examples for creating new elements, but here, my elements are already created.
I have this structure in my svg :
<g id='maingroup' class='main'>
<title>titlemain</main>
<text id='text'>textContent</text>
</g>
<g id='othergroup1' class='othergroup'>
<title>othergroup1</title>
<text id='text1'>textContent1</text>
<ellipse fill="#ac08b6" cx="198.5" cy="25" rx="27" ry="18"></ellipse>
</g>
<g id='othergroup2' class='othergroup'>
<title>othergroup2</title>
<text id='text2'>textContent2</text>
<ellipse fill="#23d5f6" cx="198.5" cy="25" rx="27" ry="18"></ellipse>
</g>
My goal is to move all ellipses into the main group to get :
<g id='maingroup' class='main'>
<title>titlemain</main>
<text id='text'>textContent</text>
<ellipse fill="#ac08b6" cx="198.5" cy="25" rx="27" ry="18"></ellipse>
<ellipse fill="#23d5f6" cx="198.5" cy="25" rx="27" ry="18"></ellipse>
</g>
I have succeeded to do this with a part in D3.js and a part with DOM manipulation.
svg = d3.select('svg')
allellipses = svg.selectAll('ellipse').nodes()
for (ell of allellipses) {document.querySelector('.main').append(ell)}
Is there a way to do it only with D3.js ? I would like to replace document.querySelector by a D3.js function. At least, to know and understand how it's working to append existing elements.
But maybe it's more efficient to use only simple DOM manipulation for this operation.