sephiith
sephiith

Reputation: 1197

Internet Explorer Object expected error

Internet Explorer Object expected error LINE: 64

The code works in Firefox and Chrome.

I keep getting an Internet explorer object expected error. I removed the afflicted code and it just keeps going until any code after line 64 is gone.

The problem starts at line 64 which is the below code:

AFFLICTED CODE:

$(document).ready(function () {
    preload(preloadi);
});

ALL JQUERY CODE:

        <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script>           
        <script type="text/javascript"> 

/* -------------------------------- Preload images function for speed*/

    function preload(arrayOfImages) {
        $('body').addClass("loading");
        $(arrayOfImages).each(function () {
            $('<img/>')[0].src = this;
        });
        $('body').removeClass("loading");
    }

/* -------------------------------- Generic functionality function */

    function transformImage(classCSS, original, link, backArray, count, prevClass) {
        var back = '<div id="back"><div id="_' + backArray[backArray.length-1] + '"></div></div><div class="_0"></div><div class="_1"></div><div class="_4"></div><a id="contact" href="mailto:[email protected]"></a><a id="rightlink" target="_blank" href="http://www.casa.gov.au/scripts/nc.dll?WCMS:STANDARD::pc=PC_101078"></a>';

        link[prevClass] = window.original;
        window.original = link[classCSS];

        if (classCSS != '0') { link[classCSS] += back; }

        $('.inter').fadeTo(250, 0.25, function () {

            $('.inter').html(link[classCSS]);


            $('.inter').css({
                'background-image': 'url("' + classCSS + '.png")'
            });
            $('.inter').fadeTo(250, 1.00);
        });
    }

/* -------------------------------- Variables */
    var preloadi = [
        '1.png',
        '2.png'
        ];  
    var backArray = [];
    var prevClass = '0';
    var classCSS = '0';
    var count = 0;
    original = '<div class="_2"></div><div class="_3"></div>';
    var link = [
    '<div class="_2"></div><div class="_3"></div>',
    'a',
    'b',
    'c',
    'd'
    ];

/* -------------------------------- Event handlers */

    $(document).ready(function () {
        preload(preloadi);
    });

    $(document).on('mouseenter mouseleave', '.inter [class]', function (event) {
        $('.' + this.classCSS + 't').toggle(event.type === 'mouseenter');
    });

    $(document).on('change', '#selectContainer [id]', function () {
    backArray[count] = classCSS;
    count += 1;
    prevClass = classCSS;

    classCSS = $("select").val();
    transformImage(classCSS, original, link, backArray, count, prevClass); 
    })

    $(document).on('click', '.inter [class], .inter #back [id]', function () {

    if (this.id) { 
    count -= 1; 
    backArray.pop(count);  
    } else { 
    backArray.push(classCSS);
    count += 1;
    }

    prevClass = classCSS;
    classCSS = (this.id || this.className).substr(1);
    transformImage(classCSS, original, link, backArray, count, prevClass); 
    })  

    </script> 

Upvotes: 1

Views: 9307

Answers (1)

user1864610
user1864610

Reputation:

Your document-ready handler is too short.

$(document).ready(function () {
   preload(preloadi);
});  // Document ready ends here.

As a result, everything below it is executing before the DOM is ready.

Move the closing }); below all your event handler code and it should work, subject to any other coding errors there might be.

What you should end up with is:

$(document).ready(function () {
  preload(preloadi);

  $(document).on('mouseenter mouseleave', '.inter [class]', function (event) {
    $('.' + this.classCSS + 't').toggle(event.type === 'mouseenter');
 });

 // more initialisation code...

});  // end of $(document).ready()

// No more code here.

Upvotes: 2

Related Questions