Skip to content

Instantly share code, notes, and snippets.

@n1n9-jp
Last active February 21, 2016 05:41
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 n1n9-jp/e92192d0f9d1c301713b to your computer and use it in GitHub Desktop.
Save n1n9-jp/e92192d0f9d1c301713b to your computer and use it in GitHub Desktop.
make radio buttons and labels dynamically.
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