At run time, the document is only partially loaded. So your script element will be the last node in the document:
var target = document.documentElement; // start at the root element while (target.childNodes.length && target.lastChild.nodeType == 1) { // find last HTMLElement child node target = target.lastChild; } // target is now the script element alert(target.parentNode); // this is p
user123444555621
source share