Skip to content

Instantly share code, notes, and snippets.

@rubensa
Last active December 14, 2021 05:35
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 rubensa/5128d5c8b85eb82ca970d89222693128 to your computer and use it in GitHub Desktop.
Save rubensa/5128d5c8b85eb82ca970d89222693128 to your computer and use it in GitHub Desktop.
Chrome DevTools Snippet to click on an element and uncheck all contained checkboxes.
// uncheck-checkboxes.js
// https://gist.github.com/rubensa/5128d5c8b85eb82ca970d89222693128
// Chrome DevTools Snippet to click on an element and uncheck all contained checkboxes.
// Starting Firefox 72, you can import a Javascript file content in the console input with Ctrl + O (Cmd + O on macOS), as well as saving the console input content to a file using Ctrl + S (Cmd + S on macOS).
(function() {
function uncheckCheckboxes(e) {
e.preventDefault();
e.stopPropagation();
window.removeEventListener('mousedown', uncheckCheckboxes, true);
var node = e.target;
console.group("uncheck-checkboxes");
console.log("Clicked on ", e.target);
var checkboxes = node.querySelectorAll("input[type=checkbox]");
console.groupCollapsed("checkboxes");
for (var i = 0; i < checkboxes.length; i++) {
var checkbox = checkboxes[i];
if (true == checkbox.checked) {
// some times the event click needs to be fired to execute the asociated functionallity
checkbox.click();
// anyway make sure the attribute is removed
checkbox.removeAttribute('checked');
// and the value is changed
checkbox.checked = false;
console.log(checkbox);
}
}
console.groupEnd("checkboxes");
console.groupEnd("uncheck-checkboxes");
}
window.addEventListener('mousedown', uncheckCheckboxes, true);
return "uncheck-checkboxes.js: Click on an element to uncheck all checkboxes contained in it";
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment