-1

Whenever I attempt to run a selection of javascript I always get the following console errors in IE7,8 or 9. However, it works fine in any other browser.

SCRIPT438: Object doesn't support property or method 'addEventListener' 
jquery-2.0.3.min.js, line 3 character 6105
SCRIPT5009: 'jQuery' is undefined 
jquery.animate-colors.js, line 8 character 1
SCRIPT5007: The value of the property '$' is null or undefined, not a Function object 
localhost, line 100 character 2

Find below the code I am attempting to run (eliminated unimportant code, jquery is loaded before any of its plugins).

<script>

$(window).load(function() {

    $("#titleFirstname").delay(200).fadeIn(500);
    $("#titleLastname").delay(450).fadeIn(500);

    $("#enterSite").delay(650).fadeIn(500);

    $("#enterSite").hover(function() {
        $(this).animate({backgroundColor: 'rgba(255, 255, 255, 0.5)'}, 100)
    }, function() {
        $(this).animate({backgroundColor: 'rgba(255, 255, 255, 0.2)'}, 100)
    });

    $("#footer").delay(500).animate({bottom: '5px'});

});

</script>


<div id="primaryContainer">
    <div id="titleFirstname">
        TEXT
    </div>

    <div id="titleLastname">
        TEXT
    </div>

    <a href="#">
        <div id="enterSite">
            ENTER SITE
        </div>
    </a>

</div>
Sam Holmes
  • 1,594
  • 13
  • 31
  • 11
    That version of jQuery doesn't support oldIE. Switch to the oldIE friendly version 1.10.2 – Kevin B Oct 03 '13 at 18:23
  • 2
    jquery 2.x.x doesn't support old IE ? – adeneo Oct 03 '13 at 18:23
  • 2
    @adeneo from the 2.0 release notes: _As promised, this version leaves behind the older Internet Explorer 6, 7, and 8 browsers..._ and _the jQuery team still supports the 1.x branch which does run on IE 6/7/8._ – Evan Davis Oct 03 '13 at 18:25
  • That worked perfectly Kevin, I completely overlooked the use of the wrong version of jquery. Would you add that as an answer so I can make it the accepted? – Sam Holmes Oct 03 '13 at 18:29
  • jQuery 2 should work on IE9 though. You're sure you get the error in IE9? Also, why are you using window.load over document ready? – j08691 Oct 03 '13 at 18:30
  • 1
    I needed to wait for the background image to load before displaying any content. – Sam Holmes Oct 03 '13 at 18:31

2 Answers2

2

with jQuery 1.10, the jQuery library split into two different branches: jQuery 1.10.x and jQuery 2.x. Both branches are being updated simultaneously and support the exact same public API. The difference between the two is 2.x will no longer support IE6/7/8, and 1.10.x will continue to support IE6/7/8 until the marketshare for all three of those versions go below a point where it isn't worth testing anymore (which isn't likely to happen any time soon.)

Use jQuery 1.10.2 unless you don't want to support oldIE.

It may be worth it to use conditional comments to include 1.10.2 for oldIE and 2.x for modern browsers, but it's just as acceptable to include 1.10.2 for all.

Kevin B
  • 94,570
  • 16
  • 163
  • 180
0

The fact that jQuery is showing up undefined, makes me think it is not properly being referenced to it's library. Another sign of this is "$" throwing an error. How are you referencing jQuery library, and are you referencing it before the function is called that you are trying to run?supported,

Casey ScriptFu Pharr
  • 1,672
  • 1
  • 16
  • 36
  • It's not defined because it errored out before it could set `window.$` and `window.jQuery` – Kevin B Oct 03 '13 at 18:29
  • That is why I thought is wasn't being referenced correctly. It may not support features of it, but basic jQuery features should still run shouldn't they? You will just fumble on features that are not compatible for IE versions. It isn't even recognizing that jQuery is running or loaded. For example, newer jQuery functions would fumble. – Casey ScriptFu Pharr Oct 03 '13 at 18:36
  • It failed to bind to the document ready event because oldIe doesn't support addEventListener. That particular line was before the line that sets the global variables, therefore the global variables never got set. – Kevin B Oct 03 '13 at 18:37
  • I see. I started using jQuery in IE 8 and 9. Thanks for the info. Yea, it uses AttachEvent, not the addEventListener. Thanks @ Kevin B. http://stackoverflow.com/questions/6927637/addeventlistener-in-internet-explorer – Casey ScriptFu Pharr Oct 03 '13 at 18:40