Created
September 6, 2017 16:48
-
-
Save mathieutu/32876fdfbc5d6c4a691a08cc2e46fe43 to your computer and use it in GitHub Desktop.
How to make parent/child 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
document.querySelector('form').addEventListener('input', (event) => { | |
let match; | |
if (match = /child-(\d+)/.exec(event.target.id) && event.target.checked) { | |
document.querySelector(`#parent-${match[1]}`).checked = true; | |
} | |
if (match = /parent-(\d+)/.exec(event.target.id) && !event.target.checked) { | |
document.querySelector(`#child-${match[1]}`).checked = false; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment