Search code examples
javascriptcheckboxfilterselectors-api

querySelectorAll checked values


I have a list/group of checkboxes, that made by php; put in name="item[]" html property, and then follow with this:

 var list = document.querySelectorAll("input[name^='item[']")

So far, works well. I need to count only the checked ones, not all like:

 list.length

How can I access the values for eachone to check "checked" property or value?


Solution

  • Rather than looking through your list, you can go back and ask querySelectorAll to return just the checked items:

    var checkedList = document.querySelectorAll("input[name^='item[']:checked")