For example, this works in mozilla, but should it?
Code:
var styleNode = document.createElementNS("http://www.w3.org/1999/xhtml", "html:style");
document.getElementsByTagName("head").item(0).appendChild(styleNode);
styleNode.appendChild(document.createTextNode("body { background-color:pink; }"));
I thought CSS rules were not text nodes in a similar way that comments and entities aren't text nodes. At any rate, this doesn't work, as I didn't think it would.
__________________
"Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark
The contents of the script and style elements should be represented as text nodes in the DOM, because that is exactly what they are in the XML document. That's not to say a style rule should be represented as a text node, however, because a style rule is not an XML construct, but a CSS construct.
Moz doesn't support innerText at all, and I don't think iew allows that easy access to the contents of the style element. (I know I had problems with it when I wrote my ViewStyles bookmarklet, which only displays external styles because of these problems I were having.)
Also, I think only the first child text node gets parsed as JavaScript/CSS in Moz, but I'm not sure as of that.
[:edit:]Seems I recalled wrong, at least when it comes to stylesheets
I tried it with a whole bunch of rules as well, in a for loop adding each rule as a new text node, and it all works fine.
I'm asking because it doesn't work in O7, and I'm not sure how to report it as a bug.
__________________
"Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark
According to the W3C, there should technically be no difference in the handling of XML or HTML/SGML between the different ways to input it. Thus, anything that you can specify in the DOM (some things are read only, though, and can't be specified by the DOM) should be handled exactly the same as if it was part of the original document source sent from the server. However, there is nothing that indicates to the parser that a style or script tag should be parsed through a parser for their respective content languages, and thus some implementations may behave differently when you use the DOM and when you include it in the original document source (they use native host parsing for the latter, but only DOM/XML/HTML for the former) - iew's not sending some form fields that are created by the DOM is a good example, though that is a bug, not a difference in features as for example the fact that op7 can't load external scripts dynamically is (both Opera and Apple tell us that they are working on this, however. They just don't have dynamical reparsing for these types objects yet).
Thanks, but I'll do it - it's CSS that's specifically of interest, because if Opera supports XHTML, but not document.write or document.styleSheets, this is going to be the only way of getting script-generated CSS onto the page.
__________________
"Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark
Come on, this is brothercake and me you're talking to. We know that already. The question was more related to whether moz's handling is correct, because in that case op7 must be wrong, and since op7 doesn't support document.styleSheets at all, nor document.write in XML mode, this would be the only way to through scripting define style rules.
As a point of interest, I won't use document.styleSheets in IE because IE has perverted the syntax. I just use document.write, which is always going to be fine, because IE doesn't support XHTML in the first place.
As far as this goes - the question is essentially resolved - mozilla supports document.styleSheets, and the original example now works in Opera. So overall, there's a reliable solution for all.
__________________
"Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark
Last edited by brothercake; 11-25-2003 at 11:49 PM..