Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Object doesn't support addEventListener IE8 in jquery

I am using Jquery 2.0.2 and I have an error in IE8:

Object doesn't support property or method 'addEventListener' jquery.min.js, line 4 character 6105

Somehow all my codes are fine with chrome and firefox, except for ie8.

Getting these errors also resulted to:

The value of the property '$' is null or undefined, not a Function object

I included the query on top of other js files I have using:

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>

I know Jquery2+ doesnt support IE8, but I dont want to use a lesser version of Jquery.

like image 786
comebal Avatar asked Aug 20 '13 04:08

comebal


2 Answers

jQuery 2.x has dropped support for IE < 9, so if you want to support IE7 & 8 then use latest version of 1.x branch - now 1.11.0

From jQuery

jQuery 2.x has the same API as jQuery 1.x, but does not support Internet Explorer 6, 7, or 8. All the notes in the jQuery 1.9 Upgrade Guide apply here as well. Since IE 6/7/8 are still relatively common, we recommend using the 1.x version unless you are certain no IE 6/7/8 users are visiting the site.

like image 143
Arun P Johny Avatar answered Nov 20 '22 07:11

Arun P Johny


jQuery 1.9 is equivalent to jQuery 2.0 as far as functionality, bug fixes, etc. They are both actively developed.

The only difference is code that provides IE compatibility was removed to make the file size and execution speed better.

If you would like to use different jQuery versions depending on the browser, you can use a conditional tag, like this.

<!--[if !IE]> -->
    <script src="jquery-2.0.0b2.js"></script>
<!-- <![endif]-->

<!--[if IE]>
    <script src="jquery-1.9.1.js"></script>
<![endif]-->

Note the styntax highlighting. The first is just two comments that are siblings of the script tag, and the latter is a comment with the script tag inside it. Browsers just follow the rules of DOM parsing, and load/execute the first script. IE deviates and won't execute the first, but will execute the latter.

like image 11
Brigand Avatar answered Nov 20 '22 08:11

Brigand