• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 274
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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