Hi,


I am attempting to add a style tag (and some styles) within the head tag.


I have attempted this using two methods and both failed in IE (InnerHTML and appendChild).


The append child method i tried looks like


Code:
function addStyles(styles) {
  
  var newStyleTag = document.createElement('style');
  newStyleTag.setAttribute('id', 'extraStyle');
  
  var head = document.getElementsByTagName('head')[0];
  
  head.appendChild(newStyleTag);

  
  var oStyles = document.createTextNode(styles);
  document.getElementById('extraStyle').appendChild(oStyles);

}

So i am basically just

  1. Creating the style tag and giving it an id
  2. appending the style tag to the head
  3. Creating a new text node and appending it to the style tag


It is failing on the last append child. The inner HTML method was failing on about the same part.


Any ideas on how i could successfully do this?