xxxxxxxxxx
Try adding the style element to the head rather than the body.
This was tested in IE (7-9), Firefox, Opera and Chrome:
var css = 'h1 { background: red; }',
head = document.head || document.getElementsByTagName('head')[0],
style = document.createElement('style');
head.appendChild(style);
if (style.styleSheet) {
style.styleSheet.cssText = css; // This is required for IE8 and below.
} else {
style.appendChild(document.createTextNode(css));
}