I have checkbox set including labels and inputs.
Initially, I've made a div as a wrapper for label and input above svg because I want to have the checkbox avobe svg. And then I bind data to make checkboxes including label and input according to nested data key.
var countryWrapper = d3.select(".checkboxWrapper")
var countryButton =
countryWrapper
.selectAll(".checkboxes")
.data(nest)
.enter()
.append("label")
.attr('for', function(d) { return d.key; })
.text(function(d) { return d.key; })
.attr("class", "checkboxes")
.attr("id", "checkbox-label")
.append("input")
.attr("type", "checkbox")
.attr("id", function(d) { return d.key; })
.attr("value", function(d) { return d.key; })
.attr("class", "checkboxes")
It works fine. But the label comes first followed by input. I'd like to have the order reversed - input(checkbox) first comes followed by label.
It could be done by making tags as many times as keys in body but want to avoid the way to make it manually.
Would it be any way to reverse order in label and input in avobe code? I found HTML attribute dir=rtl and CSS input 'float:left' / label 'float:right' But they made undesired consequences, like pushing svg into middle or putting the input/lable on the very right side when svg remained left.
Add a container for the group of elements when appending.
Add the label text after the
input
item