Javascript Toggle Checkbox
I need to toggle all buttons with a single function. Function needs to toggle all checkboxes in the document as my checkboxes are freestanding and not part of a form. I currently h
Solution 1:
Two main items to refactor. First, instead of doc
it must be document
. Second instead of relying on a global just pass in a boolean to determine whether or not to check the checkboxes.
functioncheckedAll(isChecked) {
var c = document.querySelectorAll('input[type="checkbox"]');
for (var i = 0; i < c.length; i++){
c[i].checked = isChecked;
}
}
JS Fiddle:http://jsfiddle.net/Jvnfm/107/
Post a Comment for "Javascript Toggle Checkbox"