moviewyrm/bookwyrm/static/js/check_all.js

18 lines
475 B
JavaScript
Raw Normal View History

/* exported toggleAllCheckboxes */
2021-03-19 17:51:45 +00:00
/**
* Toggle all descendant checkboxes of a target.
*
* Use `data-target="ID_OF_TARGET"` on the node being listened to.
*
* @param {Event} event - change Event
* @return {undefined}
*/
function toggleAllCheckboxes(event) {
const mainCheckbox = event.target;
document
.querySelectorAll(`#${mainCheckbox.dataset.target} [type="checkbox"]`)
.forEach(checkbox => {checkbox.checked = mainCheckbox.checked;});
}