var anchors = document.getElementsByTagName("A");

W

windandwaves

does it matter if I write

var anchors = document.getElementsByTagName("A");

or

var anchors = document.getElementsByTagName("a");

Or is there a better way to catch both <a hrefs and <A HREFS

Thanks a million

Nicolaas
 
R

RobG

does it matter if I write

var anchors = document.getElementsByTagName("A");

or

var anchors = document.getElementsByTagName("a");

No.

Since HTML tag names are not case sensitive, getElementsByTagName isn't
either. It's not specified that way, but it makes sense to be so.

Or is there a better way to catch both <a hrefs and <A HREFS

In HTML, they are identical. But you might find:

var anchors = document.links;

is more appropriate.

<URL: http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-7068919 >
 
N

Neo Geshel

RobG said:
No.

Since HTML tag names are not case sensitive, getElementsByTagName isn't
either. It's not specified that way, but it makes sense to be so.



In HTML, they are identical. But you might find:

var anchors = document.links;

is more appropriate.

<URL: http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-7068919 >

Actually, there *is* a difference!

I recently converted a set of documents to XHTML 1.1, and decided to
have the mime-type served up to all non-IE browsers as
application/xhtml+xml (with IE still getting text/html).

Well, the use of capitalized values in my getElementsByTagName() (as
well as everywhere else) ceased to work in all non-IE browsers,
especially when comparing values (==). When I changed them to lowercase,
the reverse happened (non-IE browsers suddenly worked, IE didn’t).

The trick for me was to add a .toLowerCase() to every comparison. For
example, this method:

if (item.nodeName.toLowerCase() == "a") {}

worked flawlessly across both IE and non-IE browsers.

When you get the server to set a mime-type of application/xhtml+xml,
non-IE browsers always interpret elements as they are typed (if you use
uppercase in your HTML, the JS will need uppercase references... and all
my XHTML is all in lowercase).

Even though IE doesn’t get this mime-type (it is still served up as
traditional text/html), the presence of the DOCTYPE as the first item
(the XML declaration simply isn’t added in by the server-side script)
causes IE to go into standards-compliant mode, and for some reason the
JS implemented in IE will always assume an element to be uppercase,
irregardless of how it is actually typed in the web page.

Gotta love M$ to give us such a broken and badly designed browser! No
wonder I haven’t used it in five years (aside from ensuring the work I
do functions adequately with it). Vive là Firefox!

Cheers!
...Geshel
--
*********************************************************************
My e-mail address is an automatically monitored spam honeypot. Do not
send e-mail there unless you wish to be reported as a spammer. Please
send e-mail to my first name at my last name dot org.
*********************************************************************
 

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,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top