Built with blockbuilder.org
Last active
February 5, 2016 18:47
-
-
Save hungvietdo/6959df62cd3a1c1b428a to your computer and use it in GitHub Desktop.
Button in D3
This file contains hidden or 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> | |
<head> | |
<meta charset="utf-8"> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script> | |
<style> | |
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } | |
svg { width:100%; height: 100% } | |
</style> | |
</head> | |
<body> | |
<button id="showhide" onclick()>Click me</button> | |
<script type="text/javascript"> | |
var w = 300, h = 300; | |
var color = 1; | |
var svg = d3.select("body") | |
.append("svg") | |
.attr("width", w) | |
.attr("height", h); | |
d3.select("#showhide").on("click", function(){ | |
color = color + 1; | |
if (color % 2) | |
{ | |
d3.select(this).text("Click me"); | |
//Add other code below here | |
} | |
else | |
{ | |
d3.select(this).text("Reset"); | |
//Add other code below here | |
} | |
}); | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment