As we all know, null not only does not have any properties, but their existence also can not be tested. So null.property retuns error instead of undefined. So things like if (node.nextSibling.className == ...) { ... } generate error where node has no nextSibling or if even node can be null. The obvious solution is to extend the if: if ((node) && (next = node.nextSibling) && ... ) { ... } When the