Why is nodeName sometimes all-caps in javascript DOM?
So I have a DOM document that looks essentially like this
<categories>
<category id="1"/>
<category id="2"/>
</categories>
This is how the document previews in Firebug, as I would expect.
However, when I POST this to the server, I get
<categories>
<CATEGORY id="1"/>
<CATEGORY id="2"/>开发者_如何学Python
</categories>
Indeed, doc.documentElement.firstChild.nodeName returns "CATEGORY". The nodes are added using jQuery.append('<category/>').
Why are the child tags returned in all caps?
nodeName always returns the upper case name for HTML elements in DOMs treated as HTML ... not so for XML, however.
more info here
I'm not sure if this totally answers your question, but I'm guessing that part of the answer is your file is being treated like an HTML document, at least as far as nodeName is concerned.
Correction: It's JQuery that's treating things like HTML. From this previous Stack Overflow answer:
JQuery uses a hidden div innerHTML to build the child node, that's why the capitalization differs
I'm pretty sure you're experiencing the same issue as in that previous answer.
精彩评论