Skip to content

Instantly share code, notes, and snippets.

@stesla
Created September 3, 2011 16:17
Show Gist options
  • Save stesla/1191412 to your computer and use it in GitHub Desktop.
Save stesla/1191412 to your computer and use it in GitHub Desktop.
function setAttrs(obj, attrs) {
_.each(attrs, function(value, attr) {
obj.setAttribute(attr, value);
});
};
var paper = document.getElementById("js-svg");
var svgns = "http://www.w3.org/2000/svg";
var svg = paper.appendChild(document.createElementNS(svgns,"svg"));
var rect = svg.appendChild(document.createElementNS(svgns,"rect"));
setAttrs(svg, {width: 768, height: 200});
setAttrs(rect, {x: 68, y: 50, width: 632, height: 100,
fill: "blue"});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment