Created
August 9, 2017 14:07
-
-
Save guillaumepiot/9a34734b7857e34de3d7d1a2a3fdf941 to your computer and use it in GitHub Desktop.
Javascript: Check all / Check none
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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