Created
August 29, 2014 17:28
-
-
Save sohjsolwin/53c9d94c91af4a33ac7f to your computer and use it in GitHub Desktop.
Dynamically add items to a webpage header
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
var tempChild = {}; | |
var head = document.head; | |
if (!head) head = document.getElementsByTagName('head')[0]; | |
var dynamicloads = head.getElementsByClassName('dynamicload'); | |
for (var i = 0; i < dynamicloads.length; i++) { | |
dynamicloads[0].parentNode.removeChild(dynamicloads[0]); | |
} | |
for (var i = 0; i < componentTemplate.children.length; i++) { | |
tempChild = head.querySelector('#' + componentTemplate.children[i].attributes['id'].value); | |
if (!tempChild) { | |
componentTemplate.children[i].setAttribute('class', 'dynamicload'); | |
head.appendChild(componentTemplate.children[i]); | |
i--; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment