This Javascript doesn't work in IE but works in Chrome, Firefox and Opera

Forrest

I have an image and a spinner. I have written some code to say to remove the class 'spinner' when any img has loaded. It works well in Chrome, Firefox and Opera but not Internet Explorer.

I'm on Windows 7 using Internet Explorer 11.

I have created a very basic jsfiddle example here: http://jsfiddle.net/Forresty/o8v6xsze/

For some reason, it's not working in jsfiddle in any browser, so I'm not sure if what to make of that. I have tested it with a click function, so that if I click the image the spinner class is removed, and it works. So I think it's something to do with the loading side.

I have some other javascript going on in my site that works so I don't think it's an IE specific issue.

Here is the code:

HTML:

<div class="spinner"></div>
<img class="workImage" src="http://upload.wikimedia.org/wikipedia/commons/2/23/Lake_mapourika_NZ.jpeg">

css:

.workImage{
    width: 500px;
    height: 500px;
}

.spinner{
    width: 500px;
    height: 500px;
    background: red;
}

Javascript:

$('img').on('load', function() {
    $("div").removeClass("spinner");
})

I've also tried this javascript:

$('img').load(function() {
    $('div').removeClass('spinner');
})

I've no idea what I'm missing. Any help would be appreciated.

Thanks.

Claudiu Creanga

You need to apply ondomready on the top left in jsfiddle. It is working well. I tested it in IE10 too.

http://jsfiddle.net/o8v6xsze/1/

To solve the issue in IE10, you can use:

$('img').on('load', function() {
    $("div").removeClass("spinner");
}).each(function() {
  if(this.complete) $(this).load();
});

http://jsfiddle.net/o8v6xsze/3/

It is working in my IE10.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

PagedList doesn't work on IE but works on Chrome and Firefox

From Dev

Ajax Doesn't work in Chrome,Firefox, & Opera

From Dev

Twitter bootstrap carousel works well with Chrome but doesn't on Firefox,Opera, and IE

From Dev

Javascript works in JS Fiddle but doesn't work in Chrome/IE

From Dev

Javascript works in JS Fiddle but doesn't work in Chrome/IE

From Dev

IE CSS doesn't work but in Firefox it works

From Dev

This PHP script doesn't work in Internet explorer and Microsoft Edge but works in Chrome/Firefox/Safari/Opera

From Dev

Why doesn't this css3 for vertical centering work in IE11? Works in Firefox, Chrome & Edge

From Dev

Why doesn't css work in IE when it works as expected in Firefox and Chrome?

From Dev

Javascript doesn't work in firefox and IE/edge

From Dev

JavaScript submit does not work in Chrome/Safari, but works fine in Firefox/IE

From Dev

JavaScript submit does not work in Chrome/Safari, but works fine in Firefox/IE

From Dev

Overflow hidden doesn't work on firefox, but does work in IE and chrome

From Dev

JavaScript search function works great in Chrome, Safari, and Opera, but takes forever in IE and Firefox

From Dev

JS function named `animate` doesn't work in Chrome, but works in IE

From Dev

Website doesn't Work in IE8 but works in Google Chrome

From Dev

Website doesn't Work in IE8 but works in Google Chrome

From Dev

Code working in IE and Chrome doesn't work in Firefox

From Dev

jQuery UI droppable doesn't work on IE and Firefox (but does on Chrome)

From Dev

Media query works on mobile Firefox but doesn't work on mobile Chrome

From Dev

Cytoscape.js - layout() doesn't work in Firefox, works in Chrome

From Dev

jquery-issue with load(): works with Firefox and Safari, not with Chrome, Opera and IE

From Dev

Chrome/Opera CSS display bug in Bengali/Hindu/Tamil/Urdu (doesn't happen in FireFox/IE)

From Dev

Jquery Javascript only works on chrome and firefox, but not on IE

From Dev

JavaScript not working in IE and Firefox, works fine in Chrome

From Dev

JavaScript login button works in IE but not in Chrome or Firefox

From Dev

No sound on Firefox and Opera, but works on Chrome

From Dev

No sound on Firefox and Opera, but works on Chrome

From Dev

Javascript function only works in edge not chrome, firefox or opera

Related Related

  1. 1

    PagedList doesn't work on IE but works on Chrome and Firefox

  2. 2

    Ajax Doesn't work in Chrome,Firefox, & Opera

  3. 3

    Twitter bootstrap carousel works well with Chrome but doesn't on Firefox,Opera, and IE

  4. 4

    Javascript works in JS Fiddle but doesn't work in Chrome/IE

  5. 5

    Javascript works in JS Fiddle but doesn't work in Chrome/IE

  6. 6

    IE CSS doesn't work but in Firefox it works

  7. 7

    This PHP script doesn't work in Internet explorer and Microsoft Edge but works in Chrome/Firefox/Safari/Opera

  8. 8

    Why doesn't this css3 for vertical centering work in IE11? Works in Firefox, Chrome & Edge

  9. 9

    Why doesn't css work in IE when it works as expected in Firefox and Chrome?

  10. 10

    Javascript doesn't work in firefox and IE/edge

  11. 11

    JavaScript submit does not work in Chrome/Safari, but works fine in Firefox/IE

  12. 12

    JavaScript submit does not work in Chrome/Safari, but works fine in Firefox/IE

  13. 13

    Overflow hidden doesn't work on firefox, but does work in IE and chrome

  14. 14

    JavaScript search function works great in Chrome, Safari, and Opera, but takes forever in IE and Firefox

  15. 15

    JS function named `animate` doesn't work in Chrome, but works in IE

  16. 16

    Website doesn't Work in IE8 but works in Google Chrome

  17. 17

    Website doesn't Work in IE8 but works in Google Chrome

  18. 18

    Code working in IE and Chrome doesn't work in Firefox

  19. 19

    jQuery UI droppable doesn't work on IE and Firefox (but does on Chrome)

  20. 20

    Media query works on mobile Firefox but doesn't work on mobile Chrome

  21. 21

    Cytoscape.js - layout() doesn't work in Firefox, works in Chrome

  22. 22

    jquery-issue with load(): works with Firefox and Safari, not with Chrome, Opera and IE

  23. 23

    Chrome/Opera CSS display bug in Bengali/Hindu/Tamil/Urdu (doesn't happen in FireFox/IE)

  24. 24

    Jquery Javascript only works on chrome and firefox, but not on IE

  25. 25

    JavaScript not working in IE and Firefox, works fine in Chrome

  26. 26

    JavaScript login button works in IE but not in Chrome or Firefox

  27. 27

    No sound on Firefox and Opera, but works on Chrome

  28. 28

    No sound on Firefox and Opera, but works on Chrome

  29. 29

    Javascript function only works in edge not chrome, firefox or opera

HotTag

Archive