How to embed svg to svg in js?
-
I have a code like
const newSvg = oldSvg + svg.trim() .replace(/(^<\?xml[^>]*>)|/g, '') .trim() .replace(/(^<svg[^>]*>)|(<\/svg>$)/g, ''); console.log(newSvg);
where oldSvg is the first svg and svg is the second svg.
I get newSvg in the console - it displays me an entry like& lt; svg & gt; & lt; / svg & gt; & lt; path d = "" & gt; & lt; / path & gt;
But how can I display not this entry, but so that the path is inside? Like this
<svg> <path d=""></path> </svg>
JavaScript Anonymous, Oct 7, 2019 -
const oldSvg = data.editor.svg;
const newSvg = svg.trim()
.replace(/(^<\?xml[^>]*>)|/g, '')
.trim()
.replace(/(^<svg[^>]*>)|(<\/svg>$)/g, '');
const position = oldSvg.length - 6;
const svgResult = [oldSvg.slice(0, position), newSvg, oldSvg.slice(position)].join('');
Found how to solveClara McKenzie
1 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!