You just need to get a list of all of the elements you're interested in, then you need to perform some action on them. I've added the forEachNode function, since the querySelectorAll function doesn't actually return an array - it returns a nodeList which has similar syntax and functionality as an array, but omits the forEach function.
Note: a checkbox is checked if it has the attribute checked. The actual value of the attribute is not used - it's just it's presence or lack thereof that dictates the check-state. As such, you could write anything rather than 0 to the checked attribute.
EDIT: The above note is incorrect. Both the 'checked' attribute as visible in the html and the 'checked' member variable control the state. I've updated the uncheck and check functions.
<!DOCTYPE html>
<html>
<head>
<script>
function byId(e){return document.getElementById(e);}
window.addEventListener('load', mInit, false);
function mInit()
{
}
/*
func to be called takes 3 variables. currentElement, currentIndex, nodeList the element belongs to.
*/
function forEachNode(nodeList, func)
{
var i, n = nodeList.length;
for (i=0; i<n; i++)
{
func(nodeList[i], i, nodeList);
}
}
/*
function uncheck(elem)
{
elem.removeAttribute('checked');
}
function check(elem)
{
elem.setAttribute('checked',0);
}
*/
function uncheck(elem)
{
elem.checked = false;
elem.removeAttribute('checked');
}
function check(elem)
{
elem.checked = true;
elem.setAttribute('checked',0);
}
function checkAll()
{
var checkBoxElements = document.querySelectorAll('input[type=checkbox]');
forEachNode(checkBoxElements, check);
}
function uncheckAll()
{
var checkBoxElements = document.querySelectorAll('input[type=checkbox]');
forEachNode(checkBoxElements, uncheck);
}
</script>
<style>
</style>
</head>
<body>
<button onclick='uncheckAll()'>Uncheck all</button>
<button onclick='checkAll()'>Check all</button>
<br>
<input type='checkbox'/>CB 1
<br>
<input type='checkbox'/>CB 2
<br>
<input type='checkbox'/>CB 3
<br>
<input type='checkbox'/>CB 4
<br>
<input type='checkbox'/>CB 5
<br>
</body>
</html>