Explicit check for elements from getElementsByTagName

From @nschonni's comment on #1581.