Expected identifier – Internet Explorer Error

Posted by Tom on July 20, 2010

Whilst developing Windows Web Desktop (www.leapwing.co.uk/windows/), I came across an error, or rather an avoidable glitch in Internet Explorer with Javascript Identifiers – it’s to be expected really, tut tut Microsoft!

I didn’t as such get an error message but all my jQuery and javascript stopped working just in Internet Explorer. When I went into the error console, I noticed an error -

Expected identifier

The problem is caused if you have class as an identifier because Internet Explorer reserves the name class, which I did in the following code -

var class = $('#newWindow').attr('class');
var newClass = class + 1;

$('#newWindow').removeClass(class);
$('#newWindow').addClass(newClass);

To fix the error, just change your identifiers to something else (Just add a letter onto the end or something. (Remember to update all you references to the variable). I changed the code above to the following…

var classr = $('#newWindow').attr('class');
var newClass = classr + 1;

$('#newWindow').removeClass(classr);
$('#newWindow').addClass(newClass);

Hope that helped!

13 Responses to Expected identifier – Internet Explorer Error

  1. prorockmagazine

    I would like to exchange links with your site tom.leapwing.co.uk
    Is this possible?

  2. Tom

    Thank you :)

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>