Question

javascript is not my forte, I found a navigation script that is designed exactly the way I want it (Jsfiddle below), but I cannot get it to work with IE8 (the best browser ever sarcasm).

Please Help!

http://jsfiddle.net/JSjY4/1/

window.onload = function () {
    var fine = [36, 34, 34, 34];
    var mitms = document.getElementsByClassName('mitm');
    var l0 = (mitms[0].offsetLeft + fine[0]);
    document.getElementById("nav_arrow").style.marginLeft = l0 + "px";

    for (var i = 0; i < mitms.length; i++) {

        mitms[i].fine = fine[i];

        mitms[i].onclick = function() {
            arr(this);
            var tmp = document.getElementsByClassName('mitm');


        }
    }

};

function arr(el) {
    var mitms = document.getElementsByClassName('mitm');
    var l = el.offsetLeft + el.fine;
    document.getElementById("nav_arrow").style.marginLeft = l + "px";
}
Was it helpful?

Solution

You should not use default as a variable name, as it is reserved. Just use a different name instead.

From the documentation (7.6.1.1 Keywords),

The following tokens are ECMAScript keywords and may not be used as Identifiers in ECMAScript programs:
break, do, instanceof, typeof, case else, new, var, catch, finally, return, void, continue, for, switch, while, debugger, function, this, with, default, if, throw, delete, in, try

Edit: As @CrazyTrain said, document.getElementsByClassName is not supported. You could replace it with a shim like this:

function getElementsByClassName(needle) {
    var my_array = document.getElementsByTagName("*");
    var retvalue = new Array();
    var i;
    var j;
    for (i=0,j=0;i<my_array.length;i++) {
        var c = " " + my_array[i].className + " ";
        if (c.indexOf(" " + needle + " ") != -1) retvalue[j++] = my_array[i];
    }
    return retvalue;
}

Which you would call like this:

var mitms = getElementsByClassName('mitm');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top