Fixing JavaScript errors in IE

I spent about 2 hours this evening trying to track down the problem causing obscure “Expected identifier, string or number” errors. It turns out that it was caused by having a comma after the last element of a list, e.g.

1
2
3
4
5
6
7
var list = { 
 
    foo: "bar", 
 
    bar: "foo", 
 
};

Removing the comma from ‘bar’, the last element in the list, makes IE happy. Naturally, this does not occur in either Firefox or Opera.

I discovered another issue while using prototype’s Ajax.PeriodicalUpdater. I was passing PeriodicalUpdater an element id to update, unfortunately I’d given the element id the same name as a class. However, if you try and update an element by its id and the id is the same as a class name, it will not work in IE. Example:

<p class="test">foo</p>
<p id="test">bar</p>

This works fine in Firefox, Safari and Opera - just not IE. When I tried doing this, IE removed the content within the test class and didn’t replace the content within the test id. The solution is to ensure that your CSS id’s do not clash with class names, which is probably good practice anyway.

3 Responses

  1. Figures. You’d think M$ would make it so that IE 7 would perform as well as the other browsers out there. No, they just have to do things differently, causing headaches for developers everywhere. Glad you found the problem and fixed it.

    Randy - July 2nd, 2007 at 8:32 pm
  2. Hey.. That one just saved my day…

    Thanks!

    Btw, found your site on google :)

    Dennis - February 23rd, 2008 at 7:23 am
  3. Glad it helped someone :)

    jamie - February 25th, 2008 at 8:53 am

Leave a Reply