• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 271
  • Last Modified:

JavaScript: getElementsByTagName and Case Issue

The character case for tag names depends of the document type definition.

For example, some versions of HTML use uppercase tag names while XHTML uses lowercase tag names.

What is a cross-browser solution to take both cases into account?
var items = document.getElementsByTagName("a || A");

Open in new window

0
hankknight
Asked:
hankknight
3 Solutions
 
leakim971PluritechnicianCommented:
As I know both return the same set of objects, don't worry about that
0
 
Pratima PharandeCommented:
Yes both will be same , no need to write  ("a || A");
use only one
0
 
David S.Commented:
Always specify the tag names in lowercase.  The reasoning behind that is that in HTML they're case-insensitive while in XHTML all standard elements have lowercase names.

Keep in mind that browsers will typically show uppercase tag names (regardless of the doctype) when you check the value of their nodeName or tagName properties.
0
 
hankknightAuthor Commented:
The following link has a warning under the heading: "Getting consistent results"
http://reference.sitepoint.com/javascript/Element/tagName

Are they wrong?  It sounds like things should be fine as long as I use lowercase letters in  my getElementsByTagName code.
0
 
David S.Commented:
> Are they wrong?

They're saying the same thing I said in the last sentence of my previous reply. They're just giving more details.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now