DOM objects--case sensitive or not?

R

Ruixin Wang

Hi, this question might be stupic but it's really killing me so if anyone
can help, thank you so much! I know that JavaScript is case sensitive, but
in JavaScript books I found that DOM objects are referred to using different
cases. For example, some book says "Button" object, while others say
"button" object. If "Button" or "button" is the name for a pre-defined
object, shouldn't it have consistant case?
 
M

Martin Honnen

Ruixin said:
Hi, this question might be stupic but it's really killing me so if anyone
can help, thank you so much! I know that JavaScript is case sensitive, but
in JavaScript books I found that DOM objects are referred to using different
cases. For example, some book says "Button" object, while others say
"button" object. If "Button" or "button" is the name for a pre-defined
object, shouldn't it have consistant case?

With HTML tag names are case insensitive thus if you want to use the W3C
DOM in an HTML document to create a certain element it doesn't matter
whether you use
document.createElement('button')
or
document.createElement('Button')
However if you read element.tagName in an HTML document then the browser
should expose that as upper case
http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-822762427
As for your variables names they are of course bound to JavaScript
syntax rules meaning they are case sensitive and if you have
var button = document.createElement('button')
then you need to use
button
and not
Button
in your code
 
S

SteW

Martin said:
However if you read element.tagName in an HTML document then the browser
should expose that as upper case
http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-822762427

Just for completeness:
But if the document is an XHTML document it should be exposed the way it
was written[1] - and a valid XHTML document has all elements in lower
case[2].

[1] For the benefit of XML. XML allows authors to create their own
elements and is case insensitive, so mytag, MytAG and MYTAG can all be
used for _different_ purposes within the same document - though it may
not be the best thing to do. In HTML img, ImG and IMG are all valid but
they all mean the same.

[2] XHTML is a reformulation of HTML 4 into XML and specifies all
element names and all attribute names to be lower case.

Ste W
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top