views:

104

answers:

1

IE7 and IE8 are not letting me splice my array (Safari, Chrome, Firefox work):

        lzaCreateAd1.weatherArray = new Array();
        var jWeatherIcon = $('.weatherIcon');

        jWeatherIcon.bind('click', function (){
            var targetID = $(this).attr('id') + 'Box',
            idVal = targetID.substr(5,1);

            var jTargetBox = $('#'+targetID);

            if (jTargetBox.hasClass('inactive')) {
                jTargetBox.removeClass('inactive').addClass('active');
                lzaCreateAd1.weatherArray.push(idVal);
            } else if (jTargetBox.hasClass('active')) {
                jTargetBox.removeClass('active').addClass('inactive');
                lzaCreateAd1.weatherArray.splice(lzaCreateAd1.weatherArray.indexOf(idVal),1);
            }
        });

IE throws the following error: "Object doesn't support this property or method" for this line:

lzaCreateAd1.weatherArray.splice(lzaCreateAd1.weatherArray.indexOf(idVal),1);

Any ideas? Or other ways to remove an array item by value? Thanks in advance!

+6  A: 

indexOf is not supported by Internet Explorer. You can use the jQuery $.inArray function instead.

lzaCreateAd1.weatherArray.splice($.inArray(idVal, lzaCreateAd1.weatherArray) ,1);

See: http://api.jquery.com/jQuery.inArray/

Yi Jiang
Thanks Yi Jiang!
Emile