Created
January 11, 2013 19:17
-
-
Save srstanic/4513196 to your computer and use it in GitHub Desktop.
Dom manipulation functions useful for dynamically loading scripts.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.dom = { | |
createScriptElement: function(url, async) { | |
var script = document.createElement("script"); | |
script.setAttribute("src", url); | |
if (async !== undefined) { | |
script.async = async; | |
} | |
return script; | |
}, | |
findScriptElementById: function(id) { | |
var foundScript; | |
for(var i=0, len=document.scripts.length; i<len; i++) { | |
script = document.scripts[i]; | |
if (script.id === id){ | |
foundScript = script; | |
break; | |
} | |
} | |
return foundScript; | |
}, | |
appendAfter: function(referenceNode, newNode) { | |
if (referenceNode && newNode) { | |
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling); | |
} else { | |
console.log("Tried to append " + newNode + " after " + referenceNode); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment