Last active
December 14, 2021 05:35
-
-
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.
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
// 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