Skip to content

Instantly share code, notes, and snippets.

@darrylhebbes
Created April 4, 2014 09:04
Show Gist options
  • Save darrylhebbes/9970865 to your computer and use it in GitHub Desktop.
Save darrylhebbes/9970865 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Merge SVG paths" />
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<svg>
<path id="Line1" d="M50,50
A30,30 0 0,1 35,20
L100,100"
style="stroke:#660000; fill:none;"/>
<path id="Line2" d="M110,110
L100,0"
style="stroke:#660000; fill:none;"/>
</svg>
</body>
</html>
var rootsvg = document.getElementsByTagName('svg');
var paths = document.getElementsByTagName('path');
var newPath = [];
for (var i = 0; i < paths.length; i++) {
console.log(paths[i].getAttribute('d'));
newPath.push(paths[i].getAttribute('d'));
}
var snP = newPath.join(" ");
console.log(snP);
var Line1 = paths[0];
Line1.setAttribute('d', snP);
// rootsvg.removeChild(paths[1]);
for (var i = 0; i < paths.length; i++) {
if (i >=1){
paths[i].parentNode.removeChild(paths[i]);
//rootsvg.removeChild(paths[i]);
}
}
console.info('rootsvg', rootsvg);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment