I want to get the span text value of all the childNodes within the container of the corresponding input if the Select All checkbox is selected.
My current code picks up the ‘span’.text() reference of each input label, however it will only log the label selected (childNodes (e.g. ‘7211’) if selected singularly, or the label of the Select All checkbox (e.g. ‘Accommodation and Food Services’). What I want is to get the labels for all the childNodes if the Select All label is selected. It has to reference the corresponding childNodes of the specific selectAll checkbox as there are multiple Select All elements.
var htmlObject = layerControl.getContainer().querySelectorAll('input');
$(htmlObject).on("change", function(e) {
if ($(this).is(':checked'))
console.log($(this).siblings('span').text());
})
I can reference the Select All input, and if equals true, iterate through the childNodes and grab the element text references. Something like this:
var htmlObject = layerControl.getContainer().querySelectorAll('input');
$(htmlObject).on("change", function(e) {
if ($(this).is(':checked'))
console.log($(this).siblings('span').text());
selAll= ($(this).is('.leaflet-control-layers-selector.leaflet-layerstree-sel-all-checkbox:checked'))
if (selAll == true)
$(this).each(function () {
var sthisVal = (this.checked ? $(this).val() : "")
console.log(sthisVal)
})
})
However, the childNodes are outside of the input class so this logs the value of ‘on’ for the SelectAll input checkbox. I have to reference it’s container or parentElement to cycle through the childNodes. The variable output will then log the text label.