jQuery IE Error object doesn’t support this property or method – How to fix it

As a developer, most know what a pain in the ass Internet Explorer is: mainly because the debugging is almost non-existant thanks to useless error reports like “Object does not support this property or method” that get used for hundreds of reasons. With that in mind, finding out exactly what the problem is can be tedious and tiresome.

Today, I was presented with this exact problem in one of our applications here at work. All versions of Internet Explorer seemed to be complaining this this was the root cause as to why it could not render.

To resolve it, here are the steps that were taken:

1) Ensure that all variables have been declared using var before actually assigning a value.
2) Ensure that all objects (ie: myObj : { … }) don’t have a trailing comma (,)
3) Ensure that you are not overriding system variables and/or methods that have been defined with the same variable (ie: renaming out of scope)
4) Make sure that, before attempting to append the jQuery data() method to an element, that it exists in the DOM first.

These 4 steps helped resolve my issue. In order to track it down though, you will want to use the IE Developer Script Debugger; use this by putting a break-point at both the beginnging and end of a defined function, running it, then watching where it is that the method dies before throwing the error. Then it’s just a matter of adding more breakpoints down the line until you get to the trouble spot.

Along with this issue though, there was the situation where IE was not properly rendering div attributes that were appended dynamically to the head via a method such as this:

The above will work for all major browsers EXCEPT IE (and this means all versions of IE too). The main issue we were having is that, before appending the CSS definition to the head, we were creating the element that was being affected by this CSS append. The workaround? Apply the CSS definitions in-line to the element itself instead of appending it to the head.

Also, note that if you have CSS properties that do not have proper or empty values, IE will also get pissed off and refuse to render the styles properly. So either fill the properties with default values (if they are to be blank) or leave the property definitions out completely.

Jonathon Hibbard

If you find any issues with the content on this site, please create a ticket via the github repo for this site.

You may also like...

Leave a Reply