开发者

Why is nodeName sometimes all-caps in javascript DOM?

开发者 https://www.devze.com 2022-12-24 09:24 出处:网络
So I have a DOM document that looks essentially like this <categories> <category id=\"1\"/>

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消