An IE Pitfall With Class Name Alteration
I recently used the basic principles in Validation Hints For Your Form by askthecssguy.com for a password management application. I didn't notice any problems on my speedy development machine, but when I pushed the app to some beta testers, I noticed some slower-than-expected performance in IE. As it turns out, the problem was due to the JavaScript that would update an element's class, triggered by the onkeyup event of an input field. It was slow enough to even be disruptive to the experience.
Here is an example of a function that could duplicate the slowdown in IE. It could be attached to the onkeyup event of the username field. It will provide immediate feedback by altering the class name of the field's container when criteria are met (in this case, the value being greater than 7 characters in length). Your CSS and HTML can then determine exactly what that feedback will look like.
{
var fieldset = whatYouTyped.parentNode;
var txt = whatYouTyped.value;
if (txt.length> 7) fieldset.className = "welldone";
else fieldset.className = "";
}
As it turns out, the slowdown in IE is due to a general slowdown that IE experiences anytime the class name of the element is changed. It may be unnoticeable if it happens once, but when it happens on every key press, it is noticeable. The slowdown only occurs, however, when the class name is changed, not when the value is referenced. So the easy solution is to compare the existing value to the value you want to set, and only assign the class name if it is different.
You might change the function above to look something like this.
{
var fieldset = whatYouTyped.parentNode;
var txt = whatYouTyped.value;
var newClassName = "";
if (txt.length> 7) newClassName = "welldone";
if( fieldset.className != newClassName )
fieldset.className = newClassName;
}
This will theoretically improve performance in all browsers, although it is relatively moot in Firefox, as it doesn't experience the same level of slowdown. But for IE, this tweak in your code will make a noticeable speed improvement.

June 13th, 2007 at 6:07 pm
Man, that’s a good tip. I was just working today trying to get a radio button’s onclick event to swap an image elsewhere on a page, and it worked perfectly in FF, but puked majorly in IE. I eventually bailed because it was really requested anyway and I couldn’t get it to work in IE. Bah! Evil IE. Nothing but problems and workarounds to get it to render halfway decently.
June 13th, 2007 at 6:47 pm
Yeah, irritating. I just finished my first app where I used my IE Conditional Comments idea for “fixing” a couple CSS issues that I couldn’t fix by simply fine-tuning the CSS w/o impacting FF. It was less than 10 lines of corrective code, but still irritating that I had to do it.