I am trying to create and then style a document fragment, but am having quite a bit of difficulty. Ironically, IE is not my problem!
I have this:
var newDom = document.createDocumentFragment();
newDom.appendChild(document.createElement("style"));
newDom.appendChild(document.createElement("div"));
if (newDom.childNodes[0].styleSheet){
newDom.childNodes[0].styleSheet.cssText = "div{color:red;}";
alert(newDom.childNodes[1].currentStyle.color);
}else{
newDom.childNodes[0].appendChild(document.createTextNode("div{color:red;}"));
alert(window.getComputedStyle(newDom.childNodes[1], null).color);
};
...which alerts "red" in IE7/8/9, but "rgb(0,0,0)" in FF3.0/4/10. And, yes, I will need to know what styles are applied, so I will need to read from getComputedStyle in FF (or use some other method, so long as it's reliable).
What am I doing wrong? Is this possible? (I would think/hope so...)
I've tried lots of things - like "newDom.styleSheets", which exists in IE but not FF - to no avail.
Please help - Thanks! :D