javascript - JQuery .load() not working in Internet Explorer - Stack Overflow

I am using following code for my website:<script src="jsjquery-1.10.1.js" type="text

I am using following code for my website:

<script src="js/jquery-1.10.1.js" type="text/javascript"></script>
<script src="js/jquery-migrate-1.2.1.js" type="text/javascript"></script>

<script type="text/javascript">
    $(document).ready(function() {
        $("img#logo").load(function() {
            alert('Hello');
        });
    });
</script>

And this is not working in IE but works fine in Firefox, Chrome and Safari.

I am using following code for my website:

<script src="js/jquery-1.10.1.js" type="text/javascript"></script>
<script src="js/jquery-migrate-1.2.1.js" type="text/javascript"></script>

<script type="text/javascript">
    $(document).ready(function() {
        $("img#logo").load(function() {
            alert('Hello');
        });
    });
</script>

And this is not working in IE but works fine in Firefox, Chrome and Safari.

Share Improve this question edited Jun 29, 2013 at 5:46 Fabrício Matté 70.2k27 gold badges135 silver badges167 bronze badges asked Jun 29, 2013 at 5:12 Sharda SinghSharda Singh 7473 gold badges11 silver badges19 bronze badges 2
  • possibly syntax related? looks like }); is missing after the alert – MikeM Commented Jun 29, 2013 at 5:17
  • no error in syntax I had written wrong here.. – Sharda Singh Commented Jun 29, 2013 at 5:18
Add a ment  | 

2 Answers 2

Reset to default 3

I can confirm that your code does work in IE 8 on windows 7 64 using unminified version:

<!DOCTYPE html>
<html>
 <head>
<title>test</title>
     <script type="text/javascript" src="jquery-1.10.1.js"></script>
     <script>
         $(document).ready(function () {
             console.log($.fn.jquery);
             $("img#logo").load(function () {
                 console.log('Hello');
             });
         });
     </script>
</head> 
 <body> 
     <img id="logo" src="somegig.gif" onload="console.log('load');"/>
 </body>
</html>

This will log 1.10.1 then load and then Hello, maybe you have to validate your html and make sure your html is valid maybe that's a problem.

a quick review of http://api.jquery./load-event/ provides some caveats:

Caveats of the load event when used with images

A mon challenge developers attempt to solve using the .load() shortcut is to execute a function when an image (or collection of images) have pletely loaded. There are several known caveats with this that should be noted. These are:

  • It doesn't work consistently nor reliably cross-browser
  • It doesn't fire correctly in WebKit if the image src is set to the same src as before
  • It doesn't correctly bubble up the DOM tree
  • Can cease to fire for images that already live in the browser's cache

Note the first and fourth caveats. Clear the cache and try again.

Also, do you need the jQuery migrate ? Lose it and see if it is glitching your IE

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745502128a4630463.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信