Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

IE not rendering class styles for dynamically created elements

Question posted by: poe (Newbie) on March 28th, 2008 02:30 PM
Hello,

I was working on an Ajax-based page when I came across a little problem with IE7. If I create a page element in JavaScript and give it a class (to be styled of course) IE7 does not style the element properly once its added to the page.

Case in point, I've created a validated test page, http://dev.akeenlabs.com/test_addData.html , that demonstrates what I'm talking about.

Could someone please help me find a work around and/or tell me what I'm doing wrong in creating these objects.

Thanks.
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
drhowarddrfine's Avatar
drhowarddrfine
Expert
4,237 Posts
March 28th, 2008
02:46 PM
#2

Re: IE not rendering class styles for dynamically created elements
iirc, there are issues with dynamically set styles and when they are to be changed or set. This is a javascript problem so I'm transferring it there.

Reply
pronerd's Avatar
pronerd
Expert
300 Posts
March 28th, 2008
02:56 PM
#3

Re: IE not rendering class styles for dynamically created elements
You want to set the attribute 'className' not class.

So the line
Code: ( text )
  1. newDiv.setAttribute('class', 'newDiv');


Should be

Code: ( text )
  1. newDiv.className='newDiv';

Reply
poe's Avatar
poe
Newbie
27 Posts
March 28th, 2008
02:59 PM
#4

Re: IE not rendering class styles for dynamically created elements
Quote:
Originally Posted by pronerd
You want to set the attribute 'className' not class.

So the line
Code: ( text )
  1. newDiv.setAttribute('class', 'newDiv');


Should be

Code: ( text )
  1. newDiv.className='newDiv';


Thanks, that fixed it.

Reply
Reply
Not the answer you were looking for? Post your question . . .
180,782 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Top Javascript / DHTML / Ajax Forum Contributors