JavaScript: getElementsByTagName and Case Issue

Posted on 2011-05-09
Last Modified: 2012-05-11
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

Question by:hankknight
    LVL 81

    Assisted Solution

    As I know both return the same set of objects, don't worry about that
    LVL 39

    Assisted Solution

    by:Pratima Pharande
    Yes both will be same , no need to write  ("a || A");
    use only one
    LVL 42

    Expert Comment

    by:David S.
    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.
    LVL 16

    Author Comment

    The following link has a warning under the heading: "Getting consistent results"

    Are they wrong?  It sounds like things should be fine as long as I use lowercase letters in  my getElementsByTagName code.
    LVL 42

    Accepted Solution

    > 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.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
    In Part 1 ( we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now