ghost
ghost

Reputation: 45

IE8-specific JavaScript error?

I have a problem in IE8:

function costructor(sectionId){
$('#nextG').ready(function(){
var counterBis = 0;
slider = '.slider0'+sectionId;
//sliderBox = $(slider).closest('.floatContent');
unitScrollBis = $(slider).find('.floatImg').eq(0).width();
maxImg = $(slider).find('.floatImg').length-2;
    /*problem*/
prev = "#" + $("#controller0" + sectionId).find(".controller").eq(0).attr("id");
next = "#" + $("#controller0" + sectionId).find(".controller").eq(0).attr("id");
    /*END*/
console.log(prev);
console.log(next);
makeMove(counterBis,unitScrollBis,prev,next,slider,maxImg);
function makeMove(counterBis,unitScrollBis,prev,next,slider,maxImg){
if(counterBis <= 0){
    $(prev).fadeOut("fast");
}
else if(counterBis >= maxImg){
    $(next).fadeOut("fast");
}
$(next).click(function(){
    if(counterBis <= maxImg){
        counterBis++;
        $(prev).fadeIn("fast");
        slide(counterBis);
        }
    else{
        $(next).fadeOut("fast");
    }
});
$(prev).click(function(){
    if(counterBis > 0){
        counterBis--;
        $(next).fadeIn("fast");
        slide(counterBis);
    }
    else{
        $(prev).fadeOut("fast");
    }
});
function slide(counterBis){
    $(slider).animate({
    marginLeft: '-' + (unitScrollBis*counterBis) + 'px'
},1000);
};
};

IE8 says that: SCRIPT438: Object doesn't support property or method Can anyone help me? The problem is only in IE8, I don't understand why IE can't build this string. thanks for the help

Upvotes: 3

Views: 258

Answers (1)

dsgriffin
dsgriffin

Reputation: 68616

You need to declare variables with the var keyword, otherwise older versions of IE will not recognise them and possibly break.

So change

prev = "#" + $("#controller0" + sectionId).find(".controller").eq(0).attr("id");
next = "#" + $("#controller0" + sectionId).find(".controller").eq(0).attr("id");

to

var prev = "#" + $("#controller0" + sectionId).find(".controller").eq(0).attr("id");
var next = "#" + $("#controller0" + sectionId).find(".controller").eq(0).attr("id");

and everything should work as it does in other browsers/IE9

Upvotes: 3

Related Questions