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
mands 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.
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
mands 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.
- Have you tried taking apart that jQuery chain and running each function individually? – Pointy Commented Apr 12, 2011 at 15:42
- Also: what version of jQuery is involved here? – Pointy Commented Apr 12, 2011 at 15:42
- @Pointy: jQuery 1.4.4, and no I have not tried that. – gen_Eric Commented Apr 12, 2011 at 15:45
- Hmm ... I wonder if maybe it doesn't like setting "innerHTML" when the element isn't part of the DOM yet? Seems pretty weird to me. Unfortunately I don't have access to IE at the moment (well, I guess that's not so unfortunate :-) – Pointy Commented Apr 12, 2011 at 15:53
- 1 try changing <span /> to <span></span>. i remember IE has a few bugs regarding that – yoavmatchulsky Commented Apr 12, 2011 at 15:56
2 Answers
Reset to default 2Where 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...');
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744788610a4593777.html
评论列表(0条)