Wells
Wells

Reputation: 10969

jQuery, javascript, and IE8

OK, simple:

self = $(this);

Throws a JavaScript error in IE8 when it's inside an event handler. It works in every other browser.

var self = $(this);

Throws no error. Why?

Upvotes: 1

Views: 644

Answers (1)

Pointy
Pointy

Reputation: 413727

The answer is that var keyword staring back out at you.

When you reference just plain self, you're referencing a global variable and IE won't let you change it. When you write var self you're declaring a local variable.

Upvotes: 7

Related Questions