Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IE8 errors when defining a Javascript object?

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>
like image 296
Tanoro Avatar asked Jan 14 '13 17:01

Tanoro


2 Answers

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

like image 57
Narayana Nagireddi Avatar answered Sep 30 '22 09:09

Narayana Nagireddi


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

like image 30
PickYourPoison Avatar answered Sep 30 '22 08:09

PickYourPoison