IE Javascript error "Object doesn't support this property or method" within jQuery
Asked Answered
M

3

7

For some reason, I am getting the following Javascript error in Internet Explorer 8 on line 3156 of jquery.js (version 1.4.3, non-compressed version): Object doesn't support this property or method. No error occurs in Firefox and Google Chrome.

This is the line the error occurs on:

if ( (match = Expr.leftMatch[ type ].exec( expr )) != null && match[2] ) {

Investigation (console.log(Expr.leftMatch[type])) produces the following interesting result: In Google Chrome, it outputs

/(^(?:.|\r|\n)*?):((?:[\w\u00c0-\uFFFF\-]|\\.)+)(?:\((['"]?)((?:\([^\)]+\)|[^\(\)]*)+)\3\))?(?![^\[]*\])(?![^\(]*\))/

However in Internet Explorer this is the output:

function() {
  var p = this;
  do p = p.previousSibling;
  while (p && p.nodeType != 1);
  return p;
}

On which exec cannot be called (it is undefined). The quoted function is not present within jquery.js. Does anyone have any clue why this happens, or what I can do to solve it?

I have, unfortunately, not yet been able to create a simple script to reproduce the problem, although I did find this post of someone having the same problem, but it does not offer a solution (the last post suggests the page should be run in Standards Mode, but mine already is).

Melanochroi answered 19/10, 2010 at 12:44 Comment(6)
What is the value of "type" at the point you printed that "leftMatch" entry?Surmullet
What? - Is that error message not specific enough for ya? :-D (its almost as helpful as the "Undefined is not a function" error message) ;-)Vanquish
Well, if that's true - that Sizzle's internal tables have garbage in them - then something's gone horribly wrong somewhere.Surmullet
@Pointy: Obviously, but why? And how to fix it? And why does it only happen in IE?Melanochroi
Well, I don't think I've ever seen that happen, so I'm not sure what's to be done. If you're using IE8, there are two compatibility modes to check: "Browser mode" and "Document mode". But it sounds like you're pretty sure that that's all correct.Surmullet
@Pointy: Uh, wow. I fixed it. I'll post what's wrong in a minute.Melanochroi
M
8

As it turns out, I managed to figure it out by myself after several painful hours. It appears the Sizzle selector engine breaks in this unexpected way (and only in Internet Explorer), if you have defined Object.prototype.previousObject elsewhere.

Removing that declaration, or renaming previousObject to something else fixes the problem.

The funny thing is, I even put that code there myself (the Object.prototype.previousObject = [the function in my question]), but I did not recognize the code.

Well, that's another day full of development potential wasted.

Melanochroi answered 19/10, 2010 at 13:53 Comment(0)
W
3

I have discovered the same behaviour occurs if you attempt to add a method called "inherited" to the Object.prototype, ie Object.prototype.inherited = <some func>

It affects IE6, 7 & 8 but seems to be fixed in IE9 (beta)

Watchword answered 6/12, 2010 at 14:51 Comment(0)
O
0

May be to late to respond but I had the same problem and solved with selecting elements with plain java script rather then jquery!

  var div = document.getElementById("myDiv");
  var rect = div.getBoundingClientRect();

This works some how!

Ossie answered 15/11, 2021 at 13:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.