Changed typeof HTMLElement to nodeType checkl