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

live: http://jsbin.com/geyog/5/edit

Was it helpful?

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
scroll top