简体   繁体   中英

How to manipulate existing group elements with Snap.svg

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

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 ) );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM