Names and IDs

With Internet Explorer 7 out the door with greatly improved CSS support, the IE development team can now turn their attention towards improving the browser’s JavaScript.

Aaron put out a call for suggestions on the WaSP site a while back. PPK did the same on Quirksmode. The results are being gathered together in a wishlist wiki with an eye to prioritising the bugs and fixes.

Quite a few of IE’s issues stem from the way it treats the name attribute. As documented in this email, giving an input element a name of “length” can play havoc with any JavaScript attached to that page. The same issue arises when using an ID. It turns out that IE doesn’t make much distinction between name and id. I found that out the hard way after the DOM Scripting book was published.

The image gallery example used in chapters 4, 6 and 7, features a paragraph with the ID “description”. All the code examples given in the book work just fine but I started to get bug reports from people using the image gallery script in the wild. For some reason, it just wasn’t working in Internet Explorer.

It turned out that each of these implementations had one thing in common: they were all using a meta element in the head of their pages that had name="description". As far as IE was concerned, that was the element with the unique ID “description”.

This issue has been flagged up by PPK but, alas, too late for the book.

I’m loathe to add the “description” problem to the errata because the only error I made was choosing a semantically meaningful ID that happened to clash with a common meta tag. Still, it’s something to remember for future reference: for the sake of IE, avoid using the same value for a name attribute and an id attribute on the same page.

For anybody having trouble getting the image gallery script working in the wild, try changing the “description” ID to something else and update the JavaScript accordingly.

Posted by Jeremy on Saturday, November 25th, 2006 at 7:01pm

Comments

Better yet, just don’t use the useless meta element for anything, since no search engine pays much attention to it anyway.

# Posted by Lachlan Hunt on Monday, November 27th, 2006 at 5:59am

Lachlan, Google does make use of the meta description if one is provided. It is shown in the search result list as the description for that page.

# Posted by Jeremy Keith on Monday, November 27th, 2006 at 11:29am

i also remember having problems with IE to make my javascript work when i only used the ID for an element and the only solution i found was to add a NAME with the same value to that element. quite odd…

# Posted by aNou on Monday, November 27th, 2006 at 6:48pm

Hi, if you mean "turn their attention towards … Javascript" in they way of turning it away from CSS, I don’t agree. The support for CSS has been improved but it’s still far behind all the others. When it comes to Javascript they are at least competing in the same league. Of course, we could always hope they have different groups from CSS and Javascript so prioritizing one doesn’t hurt the other…

# Posted by Emil Stenström on Tuesday, November 28th, 2006 at 2:37pm

These type of wreckless Internet Exporer bugs boil my blood. People working on the web shouldnt have to tip toe around these issues any longer. IE7 is a large advancement over 6, but I’m still disapointed by the result; I was hoping for something as solid as FF. Fat chance.

Sorry to hear about the problem Jeremy. Book was excellent.

# Posted by Steve Tucker on Friday, December 1st, 2006 at 10:34pm

I agree with Steve. Although IE7 is an improvement, I was expecting more. It’s unbelievable that a company like Microsoft can’t match Firefox’s ability.

# Posted by Jason on Friday, December 8th, 2006 at 11:52pm

Sorry. Comments are closed.

November 2006
SunMonTueWedThuFriSat
   1234
567891011
12131415161718
19202122232425
2627282930  

Recommended Reading

XML Subscribe

Grab the RSS feed for this blog.

JavaScript API

Grab the RSS feed of comments for this entry.