« Nathan Strutz Speaks on CFEclipse | ^ Main | Ajax App: cfQuickDocs »


class...Reserved in IE?

I guess so. It doesn’t seem to matter in Firefox or Safari but having a function paramater called “class” in IE will cause it to spit on you. Let me show you what I was doing.

function toggleClass(elem, class, class2){
	if(MochiKit.DOM.hasElementClass(elem, class)){
		MochiKit.DOM.setElementClass(elem, class2);
	}else{
		MochiKit.DOM.setElementClass(elem, class);
	}
}

This is nothing more than a normal JS function that receives 3 paramaters. I thought I had all of my JS working sweet for a project deadline today but turned out…in IE NONE OF MY STUFF WORKED! Wow…what a shocker.

This function uses MochiKit (which if you don’t know about you need to find out…it is phat!) in a couple places so unfamiliar functions…ignore. I’ll post more on MochiKit as I continue to use it.

So, IE kept showing me an error “Object was expected” but it was pointing me to a line of code that had nothing to do with the error which I could spend countless hours bashing IE’s error messages, related to JS that is. Cody told me it was related to the Mochi stuff but I was in denial. He was partially right though.

MochiKit wasn’t having a problem but it did make me look closer at the functions which utilized MochiKit. In doing so I found out the word “class” cannot be used as a function param. Once I changed the name of the parameter it worked perfectly fine. Here is the result.

function toggleClass(elem, c1, c2){
	if(MochiKit.DOM.hasElementClass(elem, c1)){
		MochiKit.DOM.setElementClass(elem, c2);
	}else{
		MochiKit.DOM.setElementClass(elem, c1);
	}
}

Posted by John C. Bland II on February 20, 2006 4:40 PM |

TrackBack

TrackBack URL for this entry:
http://mt.katapultmedia.com/mt-tb.cgi/43

Post a comment