/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function insertAsFirstChild(parentNode, newChildNode){ if(parentNode.hasChildNodes()){ var refNode = parentNode.childNodes[0]; parentNode.insertBefore(newChildNode, refNode); }else{ parentNode.appendChild(newChildNode); } }