Javascript Expected Identifier Error On Internet Explorer

I googled a little and found this could happen if you included an extra comma in some expressions but that wasn’t my case.

Some coffees later I found the offending code was:

var class = $(this).parent().attr('class');

Yep, class seems to be a reserved word in Internet Explorer, thanks again Microsoft for making web developers lifes so difficult.

I just changed the variable name to fix the error, something like this:

var tabClass = $(this).parent().attr('class');

A little later I found another mention of the class problem, hell!, where was this article when I was looking for the fix? It seems you can’t set classes with jQuery’s attr() method in Internet Explorer either, well, I guess that’s why we have addClass() and removeClass().

Leave a comment