Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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"/>
</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?

like image 542
harpo Avatar asked Mar 24 '10 19:03

harpo


1 Answers

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.

like image 167
Tim Goodman Avatar answered Oct 07 '22 11:10

Tim Goodman