jay
jay

Reputation: 10325

jQuery Syntax error in Safari

Can anyone tell me why this would generate a syntax error in Safari and not in Firefox?

toggle = function(){
        $("#type_new").hide();
        $("a[class^='toggle']").unbind('click').click(function(){
            $.class = $(this).attr("class");
            if($(":input."+$.class+".text").is(':visible')==true) $(this).find("small").html("Add New Type"); else $(this).find("small").html("Choose From Exisiting Types");
            $(":input."+$.class+".select").toggle();
            $(":input."+$.class+".text").toggle().val("");
        });
    };

The error comes here:

$.class = $(this).attr("class");

Any simplification is welcome as well. This works just fine in firefox. Also you might ask why it's so complicated but sometimes I'll have more than one of these on a page so I need the function to know which one to handle.

Thanks.

Upvotes: 0

Views: 811

Answers (2)

mck89
mck89

Reputation: 19231

try to replace $.class with something else beacause i think that for some browser the "class" word is reserved.

Upvotes: 0

Jonathan Lonowski
Jonathan Lonowski

Reputation: 123453

You can't define properties/variables named after a reserved word -- such as class.

This is why you find Element.className instead of Element.class in DOM.

For a list of them, see https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Reserved_Words

Upvotes: 5

Related Questions