I’m trying to add some styles into a page using javascript
var style = document.createElement("style"),
style.innerHTML = ".firstChildTest div:first-child {width: 2px;}";
But ie6-8 are throwing an error when trying to use innerHTML on a style element. I also get the same error using
style.append(document.createTextNode(".firstChildTest div:first-child {width: 2px;}"));
How do I inject styles into a style element in ie?
See the answer here: How do you copy an inline style element in IE?
Note that you need the
<p>tag in the innerHTML of the tmp_div. Without it, IE does not accept the style element.