Wednesday, July 21, 2004

What's in a NAME?

The little-used getElementsByName() method is part of the DOM Level 1 specification and is supported by both Internet Explorer and Mozilla/Firefox. getElementsByName() is part of the HTML application of the DOM, meaning it is specific to HTML documents, and explains why you won't find it in the DOM Core spec, which applies to any XML-like document.

Given a string as an argument, getElementsByName() retrieves all elements that have a NAME attribute that matches that string. Or does it?

<div name="foo">DIV one</div>
<div name="foo">DIV two</div>
<div name="foo">DIV three</div>

<script type="text/javascript">
var divs = document.getElementsByName("foo");
alert(divs.length);
</script>

Moz/Firefox will report a length of 3. MSIE will report a length of zero. Huh?

According to the HTML 4.01 spec, the only elements that support NAME attributes are BUTTON, TEXTAREA, APPLET, SELECT, FORM, FRAME, IFRAME, IMG, A, INPUT, OBJECT, MAP, PARAM and META. So to place a NAME inside a DIV is actually invalid HTML.

Moz/Firefox doesn't have a problem with this and will happily return all three DIV elements. But MSIE treats it the invalid NAME attribute as an expando attribute and excludes those elements. From the MSDN documentation:

"Elements that support both the NAME and the ID attribute are included in the collection returned by the getElementsByName method, but not elements with a NAME expando."

It seems that MSIE's implementation of getElementsByName() is actually more compliant with the W3C standard than Moz/Firefox's. Just not nearly as useful.

12 Comments:

At 6:30 AM, Blogger Mizambar 6294 said...

Last month, I earned $12,124 from Google Adsense, click here for free information to find out how you can do the same

 
At 2:14 PM, Blogger Freddies Blog said...

Last month, I earned $12,124 from Google Adsense, click here for free information to find out how you can do the same

 
At 6:23 AM, Blogger HiiFii Webservices said...

I liked you Blog so much,so i also wanted to show you some good resourses on the net.
Learn to earn 90000$/Month
For which you may also see my Personal Website
Here.
and for a Personal Education Career Tools
free Study Database.
This site is for seeing the
Hifi Electronics.
And this is for
World Class Gadgets

 
At 10:39 AM, Blogger Administrator said...

Thanks for your blog...
http://best-casino-online.t35.com
Best Online Casino

 
At 3:45 AM, Blogger ciscoblog said...

There is a resounding desire for meaningfull freeroll tournaments in which William Hill Online Casino > players at all levels have the opportunity to compete in tournament play when the prize money is huge... but the buyin is somewhat prohibitive for most.

 
At 5:46 PM, Blogger xyz said...

This is actually a huge bug in IE. It breaks both the .getElementById method, and the .getElementsByName method.

Both bugs are laid out here:

http://webbugtrack.blogspot.com/2007/08/bug-152-getelementbyid-returns.html
and
http://webbugtrack.blogspot.com/2007/08/bug-411-getelementsbyname-doesnt-work.html

With workarounds where possible.

If IE followed the specs properly, we wouldn't be in this mess.

 
At 9:48 AM, Blogger docsharp01 said...

One of the LARGEST online slots casino that accepts players from the USA is Online Slots Casinos which has 98% payouts and bonuses!

 
At 2:10 AM, Blogger merrygoland6 said...

Hi, I love your blog!
Please link to this site
http://onlinecasino-japan.blogspot.com/
Thanks!!!

Onlinecasino lovers
Merrygoland6

 
At 7:50 PM, Blogger docsharp01 said...

Excellent article and comments! I love to play penny slots online.
One of the largest online slots casino that accepts players from the USA is Online Penny Slots which has 98% payouts and bonuses!

 
At 1:03 PM, Blogger docsharp01 said...

Excellent article and commentary! I love to play penny slots online.
One of the largest online slots casino that accepts players from the USA is Online Penny Slots which has 98% payouts and bonuses!

 
At 6:23 PM, Blogger satxxkenn said...

Cool blog - Check out my site if you need help finding a good low interest credit card. Credit Cards

 
At 1:53 PM, Blogger milf said...

black mold exposureblack mold symptoms of exposurewrought iron garden gatesiron garden gates find them herefine thin hair hairstylessearch hair styles for fine thin hairnight vision binocularsbuy night vision binocularslipitor reactionslipitor allergic reactionsluxury beach resort in the philippines

afordable beach resorts in the philippineshomeopathy for eczema.baby eczema.save big with great mineral makeup bargainsmineral makeup wholesalersprodam iphone Apple prodam iphone prahacect iphone manualmanual for P 168 iphonefero 52 binocularsnight vision Fero 52 binocularsThe best night vision binoculars here

night vision binoculars bargainsfree photo albums computer programsfree software to make photo albumsfree tax formsprintable tax forms for free craftmatic air bedcraftmatic air bed adjustable info hereboyd air bedboyd night air bed lowest pricefind air beds in wisconsinbest air beds in wisconsincloud air beds

best cloud inflatable air bedssealy air beds portableportables air bedsrv luggage racksaluminum made rv luggage racksair bed raisedbest form raised air bedsaircraft support equipmentsbest support equipments for aircraftsbed air informercialsbest informercials bed airmattress sized air beds

bestair bed mattress antique doorknobsantique doorknob identification tipsdvd player troubleshootingtroubleshooting with the dvd playerflat panel television lcd vs plasmaflat panel lcd television versus plasma pic the bestThe causes of economic recessionwhat are the causes of economic recessionadjustable bed air foam The best bed air foam

hoof prints antique equestrian printsantique hoof prints equestrian printsBuy air bedadjustablebuy the best adjustable air bedsair beds canadian storesCanadian stores for air beds

migraine causemigraine treatments floridaflorida headache clinicdrying dessicantair drying dessicantdessicant air dryerpediatric asthmaasthma specialistasthma children specialistcarpet cleaning dallas txcarpet cleaners dallascarpet cleaning dallas

 

Post a Comment

<< Home