Skip to content

Instantly share code, notes, and snippets.

@NelsonMinar
Created April 6, 2011 22:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NelsonMinar/906688 to your computer and use it in GitHub Desktop.
Save NelsonMinar/906688 to your computer and use it in GitHub Desktop.
D3 id selection example
<!DOCTYPE html>
<html><head><script type="text/javascript" src="https://github.com/mbostock/d3/raw/master/d3.js"></script></head><body>
<script lang="text/javascript">
window.onload = function() {
// Create a red rectangle
d3.select("body").append("svg:svg")
.attr("width", "100").attr("height", "100")
.append("svg:rect")
.attr("id", "myrectangle")
.style("fill", "red")
.attr("width", "100").attr("height", "100");
// Now turn the rectangle blue, via an ID selector
setTimeout(function() {
d3.selectAll("#myrectangle").style("fill", "blue");
}, 2000);
}
</script></body></html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment