dynamically created elements and the ie7 script

As you all know, IE is a stupid browser. Luckily, most of the problems with its CSS compliance (and some JavaScript problems as well) can be fixed by applying the IE7 script to the code.

I had a frustrating problem this morning, where I was upgrading my CMS to use hierarchical menus in the administration area (I’ll write about the methods used, later today). The script for that rewrites a <ul> and creates a hierarchical menu from it, which is styled with classes.

The problem was that, once the IE7 script and the hierarchical menu (I call it “magicmenu”) had run, IE simply ignored the classes I’d created.

Eventually I narrowed it down to the order that the scripts were running.

It seems that IE7 removes all class info from elements, adds its own versions of them, and rewrites the existing styles to match the new identifiers. This is grand with simple sites, but hell with dynamic ones.

So, the solution is to run IE7 after all other potential style creation/editing has been done.