5

I knew IE8 was a pain, but I have never seen it give me such trouble. All I am trying to do is define a Javascript object and it causes an error, stopping all scripting from working on the page.

The error is "Expected identifier, string or number" and indicates that the issue happens where I define the property "class" below. I have seen countless scripts define objects this way, so why does IE8 vomit on this?

I isolated the offending code to this. Placing this in the head of an HTML page by itself and running it in IE8 will cause the issue I am seeing.

<script type="text/javascript" language="javascript">
var atts = {class: "trigger"};
</script>
Tanoro
  • 871
  • 2
  • 10
  • 30
  • 2
    IE is horrible for "reserved words" that aren't. try changing class to something else temporarily, e.g. "foo", and see what happens. – Marc B Jan 14 '13 at 17:37

3 Answers3

6

It is because class is a reserved keyword. Try putting quotes around it 'class'

Matt
  • 74,352
  • 26
  • 153
  • 180
PickYourPoison
  • 108
  • 2
  • 8
6

Define using appropriate data type by enclosing in quotes, "class"

Narayana Nagireddi
  • 729
  • 1
  • 13
  • 33
0

in addtion to @PickYourPoison answer you can also use this trick:

var atts= {};
atts["class"] = "LOL";
Fareed Alnamrouti
  • 30,771
  • 4
  • 85
  • 76