Removed incorrect check for template.content.ownerDocument (template content is not part of the DOM)