Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old January 24th, 2007, 08:55 PM
windandwaves
Guest
 
Posts: n/a
Default 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

  #2  
Old January 24th, 2007, 09:15 PM
RobG
Guest
 
Posts: n/a
Default Re: var anchors = document.getElementsByTagName("A");



On Jan 25, 6:45 am, "windandwaves" <nfranc...@gmail.comwrote:
Quote:
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.

Quote:
>
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

  #3  
Old January 24th, 2007, 10:25 PM
windandwaves
Guest
 
Posts: n/a
Default Re: var anchors = document.getElementsByTagName("A");



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

  #4  
Old January 25th, 2007, 06:35 PM
Neo Geshel
Guest
 
Posts: n/a
Default Re: var anchors = document.getElementsByTagName("A");

RobG wrote:
Quote:

On Jan 25, 6:45 am, "windandwaves" <nfranc...@gmail.comwrote:
Quote:
>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.

Quote:
>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.
************************************************** *******************
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,248 network members.