Reputation: 14825
I'm trying to write a little jQuery plugin but I've problems with (of course) Internet Explorer 9.
This is the code:
$.fn.mytest = $.mytest = function() {
if ( !! this && this.call && this.apply) {
self = $("a");
} else {
self = this;
}
if(self.is(".stupid")) {
alert("yes, it's stupid");
} else{
alert("no, maybe you are");
}
return this;
};
$.mytest();
$("a").mytest();
Fiddle:
http://jsfiddle.net/Abb6a/1/
On Google Chrome everything works fine, in IE9 it says that the object does not supports the property or the method "is"
.
Looks like IE9 doesn't like the standalone version of my plugin and has troubles with the passed argument this
.
How can I solve this trouble?
Upvotes: 0
Views: 262
Reputation: 23406
self
is a property of window
object, and it's read-only in some versions of IE. To fix the problem, just rename your variable. Or if it's purposed to be used in a particular function scope only, you can declare it with var
.
Looks like all properties of window
referring a window object like top
, parent
, frames*
, self
, frameElement*
... are read-only in IE. Though self
can be overridden in IE>9.
*
= frames
is a HTMLCollection, frameElement
refers to HTML(I)frameElement
, both of these actually contain window object(s).
Upvotes: 4