Skip to content

Instantly share code, notes, and snippets.

@guillaumepiot
Created August 9, 2017 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guillaumepiot/9a34734b7857e34de3d7d1a2a3fdf941 to your computer and use it in GitHub Desktop.
Save guillaumepiot/9a34734b7857e34de3d7d1a2a3fdf941 to your computer and use it in GitHub Desktop.
Javascript: Check all / Check none
function toggleCheckboxes(){
var checkboxes = document.querySelectorAll("[name=accommodation]")
var allChecked = Array.prototype.every.call(checkboxes, function(item){ return item.checked })
if (allChecked) {
checkboxes.forEach(function(item){ item.checked = false })
} else {
checkboxes.forEach(function(item){ item.checked = true })
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment