tags:

views:

139

answers:

2

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.

+2  A: 

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

Jonathan Lonowski
+1. Also, the reason it works in Firefox is that this restriction on property identifiers will be removed in the forthcoming ECMAScript version 5 specification, and recent versions of Firefox already implement some parts of that spec.
NickFitz
Excellent thanks Jonathan. Any suggestions on simplifying that code?
jeerose
A: 

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

mck89