Created
April 6, 2011 22:34
-
-
Save NelsonMinar/906688 to your computer and use it in GitHub Desktop.
D3 id selection example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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