3

I am creating a set of checkboxes dynamically using Dojo 1.8. After creating the checkbox, I'm also setting the label for the checkbox, but the label is not visible on the site, although I can see it when I look at the HTML in Firebug. Any ideas what I am doing wrong? I've looked at the code too much at this point and can't figure out what it is. Thank you!

var checkboxContainer = dom.byId('divLayers');
var chkboxId = 'chk' + layer.id;
var chkbox = new dijit.form.CheckBox({
    id: chkboxId,
    checked: layer.visible,
    onClick: lang.hitch(this, this.toggleLayerVisibility)
});
chkbox.placeAt(checkboxContainer);
chkbox.domNode.appendChild(domConstruct.create('label', { 'for': chkboxId, innerHTML: layer.name }));
Emmster
  • 159
  • 1
  • 8

1 Answers1

2

I swear, I can spend hours trying to figure something out and then the minute I post it online for all to see, I solve my own problem. shaking head

The solution is below.

var chkboxId = 'chk' + layer.id;
var chkbox = new dijit.form.CheckBox({
    id: chkboxId,
    checked: layer.visible,
    onClick: lang.hitch(this, this.toggleLayerVisibility)
});
chkbox.placeAt(checkboxContainer);
var lbl = domConstruct.create('label', {
    'for': chkboxId,
    'innerHTML': layer.name
});
checkboxContainer.appendChild(lbl);
Emmster
  • 159
  • 1
  • 8