IE 6/7 javascript class assignment for newly created elements

C

Craig Taylor

I have a javascript function as follows: (without the prefixed *'s)

function addTest( )
{
ePop = document.getElementById( "popups" );
eWin2 = document.createElement( "div");
eWin2.setAttribute( 'id', 'win2' );
eWin2.setAttribute( 'name', 'win2' );
eWin2.setAttribute( 'class', 'window' );
** eWin2.style.backgroundColor = 'yellow';
** eWin2.style.position = 'absolute';
eWin2.style.width = '300px';
eWin2.style.height='200px';
eWin2.style.border='3px';
eWin2.style.left='150px';
eWin2.style.top='20px';
eWin2.style.zIndex='105';
eTxt3 = document.createTextNode( "This is window 2 that did not
load");
eWin2.appendChild( eTxt3 );
ePop.appendChild( eWin2 );

setWindowTo( 'win2', 'anotherPage.html' );
}

I'm finding that in IE6/7 I'm having to explicitly put the style
declerations that are in the 'window' class definition or they don't
get propogated into the element. Firefox does not display this
behavior.

Has anyone else run into similair issues / is their another way that I
should be setting the class value for a newly created element?

Thanks,

- Craig Taylor
www.ctalkobt.net
 
M

Martin Honnen

Craig said:
eWin2 = document.createElement( "div");

eWin2.setAttribute( 'class', 'window' );

Use
eWin2.className = 'window';
instead of setAttribute.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top