Skip to content

Instantly share code, notes, and snippets.

Last active February 14, 2020 14:28
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Uncheck input.checkbox-scope-control[type=checkbox] on a click outside .checkbox-scope
(function (w) {
function closeScopedCheckboxes(checkbox_selector, scope_selector) {
return function (event) {
var el =;
.forEach(function(toggleScope) {
if (!toggleScope.contains(el)) {
.filter(function (checkbox) {
return checkbox.checked && !(el instanceof HTMLLabelElement && checkbox == el.control);
.map(function (checkbox) {
checkbox.checked = false;
document.addEventListener('click', closeScopedCheckboxes('.checkbox-scope-control', '.checkbox-scope'));
document.addEventListener('touchend', closeScopedCheckboxes('.checkbox-scope-control', '.checkbox-scope'));
"name": "checkboxscope",
"version": "0.1.0"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment