Skip to content

Instantly share code, notes, and snippets.

@biovisualize
Created October 3, 2011 03:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save biovisualize/1258361 to your computer and use it in GitHub Desktop.
Save biovisualize/1258361 to your computer and use it in GitHub Desktop.
Append node already in the DOM
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js"></script>
<title></title>
</head>
<style type="text/css">
</style>
<body>
<div id="viz">
<script type="text/javascript">
var toAppend = d3.select("#viz")
.append("svg:circle")
.attr("cx", 50)
.attr("cy", 50)
.attr("r", 25)
.attr("fill", "dodgerblue");
var importedNode = document.importNode(toAppend.node(), true);
var rootSVG = d3.select("#viz")
.append("svg:svg")
.attr("width", 200)
.attr("height", 100)
.style("background-color", "skyblue");
rootSVG.append("svg:rect")
.attr("x", 50)
.attr("y", 10)
.attr("width", 100)
.attr("height", 75)
.attr("fill", "blue");
rootSVG.node().appendChild(importedNode);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment