简体   繁体   中英

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.

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

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...');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM