How can I copy ALL the attributes and styling from one svg to another svg using js please?
-
21-12-2019 - |
Question
The following code will copy ONE attribute: 'fill-rule' from svg(external svg) to snap paper(internal svg). How can I copy ALL the attributes and syling from one svg to another svg please? Any ideas would be greatly appreciated.
s1.attr("fill-rule", svg.node.getAttribute("fill-rule"));
Edit: If I use Roberts code, why this doesn't copy the attrs from svg to s1?:
s1.attr(attrs.item(i).svg);
Solution
there's an attributes property in the DOM
if you had
<svg id="svg" preserveAspectRatio="none" width="100%"/>
you can do this...
var svg = document.getElementById("svg");
for (var i=0, attrs=svg.attributes, l=attrs.length; i<l; i++){
s1.attr(attrs.item(i).nodeName, attrs.item(i).value);
}
presumably in your case it would be
var svg = svg.node;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow