0

I have this internal application that I made. It works fine in IE9 (and all the other browsers) but some of the internal users are still on IE8.

The line causing the problem is:

var thisClass = $thisElement.attributes.class.value;  

I get the error message is "SCRIPT1010: Expected identifier" and the marker is just before the c in class.

Here is the code:

$(document).on('click', function(){ 
var $this = $(this);
var $thisElement = $this.context.activeElement;
if ($thisElement != null && $thisElement.attributes.type != null && $thisElement.attributes.type.value == "checkbox"   ){
        var thisClass = $thisElement.attributes.class.value;
        var thisValue = $thisElement.value;
        if (thisValue == "All"){
            if($thisElement.checked){
                $('input[class="'+thisClass+'"]').each(function(i){
                        var checkboxValue = $(this).val();
                        $("#"+thisClass+checkboxValue).prop('checked',true);
                 });

            }else {             
                $('input[class="'+thisClass+'"]').each(function(i){
                    var checkboxValue = $(this).val();
                    $("#"+thisClass+checkboxValue).prop('checked',false);
                });                 
            }               
        }else // since the val is not = all we want to uncheck the all box if any of the bottom boxes is unchecked
        if (!$thisElement.checked){                 
                $("#"+thisClass+"All").prop('checked',false);
        }
        cnse.checkTheCheckboxes();
    }else{
        return;
    };// end if it is a checkbox
});

2 Answers2

3

ECMAScript 3-based engines, like that in IE8, don't allow reserved words to be used as identifiers with dot notation. For them, you'll need to quote class using bracket notation:

var thisClass = $thisElement.attributes["class"].value;

ECMAScript 5 changed a few use cases to allow using Identifier Names rather than just Identifiers, including with dot notation. Which is why it works in IE9.

You can also simply use the className property, as Marc suggested, as that isn't a reserved word.

Community
  • 1
  • 1
Jonathan Lonowski
  • 121,453
  • 34
  • 200
  • 199
1

If you're looking to get the class of an element in HTML, you want to use the className attribute on the element itself:

var thisClass = $thisElement.className;
Marc Baumbach
  • 10,323
  • 2
  • 30
  • 45