Click to See Complete Forum and Search --> : appendChild and css not working well on IE


nleco
June 6th, 2005, 04:47 PM
Here's my project.

i have a div that has 5 divs inside, each a container outlining a profile. when you click on arrows on each side, i'll replace the 5 people with 5 other people, via JS. things work great on mozilla, but IE is giving me one problem. it doesnt apply the CSS to the newly inserted boxes. has anyone had problems with this? i kinda do something like

<div id="container">
<div id="box1"></div>....<div id="box5"></div>
</div>

and the js does something like:

var cont = document.getElementById('container');
cont.innerHTML = "";
for(//for the next 5 people) {
//getBox returns a div object with what the new box should have, css classes added too.
cont.appendChild(getBox(index));
}


of course theres more stuff in the html. but thats the basic idea. I"m not sure why IE isnt applying the css to the newley appended children.

nleco
June 6th, 2005, 06:33 PM
i actually figured it out with a friend's help. here's the problem.

I was using the DOM function setAttribute like so
divelement.setAttribute("class", "whatever").

IE doesnt like that, it needs to be:
divelement.setAttribute("className", "whatever").

i went with a diferent way that works for both:
divelement.className = "whatever".

hope this helps someone.

Dr. Script
June 6th, 2005, 06:41 PM
Good for you finding that. Referring to .className is the universal way to do it, so that would be desired, as you found out.