Skip to content

Instantly share code, notes, and snippets.

@sohjsolwin
Created August 29, 2014 17:28
Show Gist options
  • Save sohjsolwin/53c9d94c91af4a33ac7f to your computer and use it in GitHub Desktop.
Save sohjsolwin/53c9d94c91af4a33ac7f to your computer and use it in GitHub Desktop.
Dynamically add items to a webpage header
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