How to manipulate existing group elements with Snap.svg

991 views Asked by At

We have an existing svg-document in witch we want to replace a group-element with a new one. Is it possible to do with Snap.svg?

var oldGroup = Snap.select("[id='" + oldGroupId + "']");

oldGroup.outerSVG(newGroup); //This is what I want to do but outerSVG is readonly
1

There are 1 answers

3
Ian On BEST ANSWER

You can't relace an element using just outerSVG. You haven't included enough information to give a complete correct answer, as we can't see what the existing elements, but it may be something like..

var parent = oldGroup.parent();
oldGroup.remove();
parent.add( newGroup ) 

This would depend on what 'newGroup' is. If its a DOM element, I think it would work. If its just some SVG Markup, you would probably need to do something like

parent.add( Snap.parse( newGroup ) );