JQuery 2.0.3 does not work with IE

I have the following html file example:

<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Example</title> <script src="../Scripts/jquery-2.0.3.js"></script> <!--<script src="../Scripts/jquery-1.7.js"></script>--> <script type="text/javascript"> $(document).ready(function () { $('#mainheader').css("color", "red"); }); </script> </head> <body> <h1 id="mainheader" class="header">Sample 1</h1> <h2 class="header info">Sample 2</h2> <h3 class="info">Sample 3</h3> </body> </html> 

When I run the same with jQuery version 2.0.3, it encounters an error:

Unhandled exception on line 834, column 4 in / Scripts / jquery -2.0.3.js

0x800a01b6 - Microsoft JScript Runtime Error: Object does not support this property or method

On line: // Use callback of useful event document.addEventListener ("DOMContentLoaded", completed, false);

But if I run a lower version, i.e. 1.7, it works fine ...

However, the above code works fine for both versions in Chrome.

Could you help me deal with the differences:

Thanks and respect.

+7
jquery
source share
6 answers

Currently jQuery 2.x "does not support Internet Explorer 6, 7, or 8"

From http://api.jquery.com/jQuery.browser/ :

+11
source share

Since no one mentioned this (and it was called in the comments), here is another possible way to resolve this. This is actually how I recommend you roll back your uptime compatibility and how I will carry it out in my projects.

As already mentioned, jQuery 2.x supports IE8 and lower ( with a lot of major changes starting from 1.9 even ). The reason for the fall is the goal of a smaller overall file size and higher performance.

Allegedly, the ideal target for the application would be to use jQuery 2.x for supported browsers, offering compatibility for browsers that do not.

So, I recommend just using the jQuery 2.x file (something you should use anyway if you are thinking about the future for your application). There is not much here; just add to your jQuery as before.

 <!-- according to h5bp --> <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script> <script>window.jQuery || document.write('<script src="js/vendor/jquery-2.0.3.min.js"><\/script>')</script> 

Then, to ensure compatibility with older versions of IE, you can conditionally include a patch file so that it can be processed if necessary.

 <!--[if lte IE 8]> <script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script> <![endif]--> 

This ensures that you have a faster, more compact jQuery for supported browsers and working jQuery for others, due to what is basically equivalent to an additional HTTP call (and possibly a larger total payload) when you need a patch .

+5
source share

From the site :

jQuery 2.x has the same API as jQuery 1.x, but does not support Internet Explorer 6, 7, or 8.

Use versions 1.x if you need to be compatible with older IE browsers (or the latest in compatibility mode). Version 2.x is a branch that removed a lot of materials, the only use of which was compatible with these old browsers.

+2
source share

Thats because of version 2.0.3 it doesn't support IE8 and 1.7 does

+2
source share

JQuery 2+ version does not support IE <9, if you plan to support these browsers, please stick to the latest version of 1.x branch - now 1.10.2

+2
source share

For IE 11, your HTML page should say

 <!DOCTYPE html> <html> <head> <meta http-equiv="X-UA-Compatible" content="IE=edge;" /> 

If you have an old doctype html 4.01 tag, it does not work.

0
source share

All Articles