Last active
February 21, 2016 05:41
-
-
Save n1n9-jp/e92192d0f9d1c301713b to your computer and use it in GitHub Desktop.
make radio buttons and labels dynamically.
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
var menuID = 0; | |
var menuItems = d3.select("#navBlock").append('form').selectAll("span") | |
.data( dataArray ) | |
.enter().append("span").attr("class", "navColumn"); | |
menuItems.append("input") | |
.attr({ | |
type: "radio", | |
class: "nav", | |
name: "nav", | |
value: function(d, i) {return i;} | |
}) | |
.attr('id', function(d, i) { | |
return "id" + i; | |
}) | |
.attr('value', function(d, i) { | |
return dataArray[i]; | |
}) | |
.property("checked", function(d, i) { | |
if (i === menuID) { return true; } else { return false; }; | |
}) | |
.on("change", function(d,i){ | |
menuID = i; | |
}); | |
menuItems.append("label") | |
.attr('for', function(d, i) { | |
return "id" + i; | |
}) | |
.text(function(d,i) { | |
return dataArray[i]; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment