gen_Eric
gen_Eric

Reputation: 227270

Unexpected call to method or property access in IE 7

For work, I need to get our site working in IE7. Because, as we all know, the corporate world can't upgrade.

I am using IE8's IE7 emulation mode to test the site, and using IE8's wonderful debugger has been a nightmare.

My most recent problem is the following error:

Unexpected call to method or property access.  jquery.js, line 113 character 460

I've put console.log commands on every line of my function, and figured out the line that's causing the error.

var $loading = $('<span/>').addClass('span-icon icon-ajax-loader').html('Loading...');

This line works fine in Firefox and Chrome. Oh, and it works fine when entering it into IE8's JavaScript console.

Why would this line give Unexpected call to method or property access? I think the call to the method or property was totally expected.

UPDATE: As per @Pointy's suggestion I broke that line into 3 lines.

var $loading = $('<span/>');
$loading.addClass('span-icon icon-ajax-loader');
$loading.html('Loading...');

Now I'm getting the error on this call $loading.html('Loading...');. Again, if I paste this code into IE8's developer tools and run it, it works fine.

Upvotes: 4

Views: 7021

Answers (2)

gen_Eric
gen_Eric

Reputation: 227270

Thanks to @daniellmb and @yoavmatchulsky for helping me fix this issue.

There are actually 3 separate solutions.

Use .text() instead of .html().

var $loading = $('<span/>').addClass('span-icon icon-ajax-loader').text('Loading...');

Wrap the .html() in span tags.

var $loading = $('<span/>').addClass('span-icon icon-ajax-loader').html('<span>Loading...</span>');

Or replace $('<span/>') with $('<span></span>').

var $loading = $('<span></span>').addClass('span-icon icon-ajax-loader').html('Loading...');

Upvotes: 2

SavoryBytes
SavoryBytes

Reputation: 36236

Where are you injecting the content? Have you looked at this question and answer? Javascript IE error: unexpected call to method or property access

Upvotes: 2

Related Questions