Skip to content

Instantly share code, notes, and snippets.

@p34eu
Last active July 28, 2016 17:57
Show Gist options
  • Save p34eu/7f9d06ed56ad7cb1aa20c7294ec675da to your computer and use it in GitHub Desktop.
Save p34eu/7f9d06ed56ad7cb1aa20c7294ec675da to your computer and use it in GitHub Desktop.
/*
<a class="btn btn-link" data-checkall=".chst">check all</a>
<a class="btn btn-link" data-uncheckall=".chst">uncheck all</a>
*/
var changeBoxesEvent = document.createEvent('HTMLEvents');
changeBoxesEvent.initEvent('change', true, false);
var t = document.querySelectorAll('[data-uncheckall]');
if (t) {
[].forEach.call(t, function (el) {
var targets = document.querySelectorAll(el.getAttribute('data-uncheckall')) || [];
if (targets.length) {
el.addEventListener('click', function () {
targets.forEach(function (target) {
if (!target.checked == false) {
target.checked = false;
target.dispatchEvent(changeBoxesEvent);
}
});
});
}
});
}
var t = document.querySelectorAll('[data-checkall]');
if (t) {
[].forEach.call(t, function (el) {
var targets = document.querySelectorAll(el.getAttribute('data-checkall')) || [];
if (targets.length) {
el.addEventListener('click', function () {
targets.forEach(function (target) {
if (!target.checked) {
target.checked = true;
target.dispatchEvent(changeBoxesEvent);
}
});
});
}
});
}
delete(t);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment