I'm getting w3c validation errors with this Javascript code and wonder if a kind gent/lady would spare me a moment to take a gander.
// hide all element nodes within some parent element
function hideAll(parent) {
var children = parent.childNodes, child;
// loop all the parent's children
for (var idx=0, len = children.length; idx<len; ++idx) { /* ERROR HERE */
child = children.item(idx);
// if element node (not comment- or textnode)
if (child.nodeType===1) {
// hide it
child.style.display = 'none';
}
}
}
The Errors are:
- element "len" undefined
- character ";" not allowed in attribute specification list
The semi-colon at idx<len; is where it goes wrong.
Can someone explain where I'm going wrong with the above code snippet?
Many thanks.