Help needed with creating a single select/deselect all checkbox in Typescript. The current code successfully selects all when checked but fails to deselect all when unchecked.
selectAllLocations() {
var selectAll = < HTMLInputElement > document.getElementById("allLocations");
let locationElements: NodeListOf < Element > = document.getElementsByClassName("route-location-list");
for (var i = 0; i < locationElements.length; i++) {
if (selectAll.checked && (( < HTMLInputElement > locationElements[i]).checked == false)) {
( < HTMLInputElement > locationElements[i]).click();
} else if ((!selectAll.checked) && ( < HTMLInputElement > locationElements[i]).checked) {
( < HTMLInputElement > locationElements[i]).click();
}
}
}