468,101 Members | 1,464 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,101 developers. It's quick & easy.

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

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

Jan 24 '07 #1
3 16002


On Jan 25, 6:45 am, "windandwaves" <nfranc...@gmail.comwrote:
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-HTM...tml#ID-7068919 >
--
Rob

Jan 24 '07 #2


On Jan 25, 10:07 am, "RobG" <r...@iinet.net.auwrote:
Thanks Rob G. Your help is always extremely appreciated!

Jan 24 '07 #3
RobG wrote:

On Jan 25, 6:45 am, "windandwaves" <nfranc...@gmail.comwrote:
>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-HTM...tml#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.
************************************************** *******************
Jan 25 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Claus - Arcolutions | last post: by
reply views Thread by =?Utf-8?B?QXR1bA==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.