Hi All,
I'm using the following from the ESRI JS samples to toggle my layers on and off, and it works well enough: Toggle layer visibility | ArcGIS API for JavaScript
However, getting each checkbox by its id seems a rather bloated way of doing things when you're working with ~100 layers. I'm pretty new to javascript so I'm not sure of the syntax to get the checkboxes by class, or if this can even work?
I've tried multiple id's:
on(dom.byId("chkVFPABoundary", "chkMunicipalBoundaries"), "change", updateCadastralLayerVisibility);
Which didn't work. Also:
on(document.getElementsByClassName(".cadastral_list_item"), "change", updateCadastralLayerVisibility); //Anything in my cadastral service has this class name
Which didn't work. I'm pretty sure I can't use 'on' with document.getElementsByClassName? Is there something comparable?
I tried jquery:
$('.cadastral_list_item').change(function() { if(this.checked) { updateCadastralLayerVisibility() } });
This didn't work either, nothing happens at all when the checkbox is clicked.
I've been scouring the internet all day, but can't find any clues. Thanks in advance.
Solved! Go to Solution.
How about
on(document.body, ".cadastral_list_item:change", updateCadastralLayerVisibility);
Any better?
How about
on(document.body, ".cadastral_list_item:change", updateCadastralLayerVisibility);
Any better?
Works perfectly - thank you Rene.