check node type rather than check against global 'document'