I have access to each of the li[i] that returns what you see in the picture. An example would be li[i].innerText
returns business
. How can I get the checked
state of each element?
//loop through li elements in categories to add listeners
for(var i = 0 ; i < li.length; i++){
(function(i){
li[i].addEventListener('click', function(event) {
event.preventDefault();
//disallow repeats
if(checkedItems.indexOf(li[i].innerText) == -1){
checkedItems[counter] = li[i].innerText;
counter++;
console.log("added");
}
console.log(li[i].checked); //undefined
//remove element if unchecked from array
if(li[i].checked){
var index = checkedItems.indexOf(li[i].innerText);
console.log(li[i].innerText +": " + index);
checkedItems.splice(index, 1);
console.log("disabled");
counter--;
}
console.log(checkedItems);
});
}(i));
}