View Full Version : Styling Markup on the fly

07-13-2006, 07:56 PM

I'm creating an H3 element with script like so:

var equip_span = document.createElement("h3");
equip_span.setAttribute("class", "title_equip");

Then in the css I'm styling like this:

h3.title_equip {

This works great in Firefox but for some reason IE6 does not style the H3. If I change the attribute from "class" to "id" and then style with h3#title_equip, it DOES work in IE.

But, this H3 element is not unique and is created a number of times, so I want it to be a class rather than id. Any ideas why IE is not recognizing the class?

Thanks in advance,

07-13-2006, 08:07 PM
You need to use className and IE sometimes doesn't like it when you use setAttribute for certain attributes so I recommend the DOM1 method.

var equip_span = document.createElement("h3");
equip_span.className = "title_equip";

07-13-2006, 08:12 PM
That's It!

Thank You!