IE not rendering class styles for dynamically created elements

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • poe
    New Member
    • Jun 2007
    • 32

    IE not rendering class styles for dynamically created elements

    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.
  • drhowarddrfine
    Recognized Expert Expert
    • Sep 2006
    • 7434

    #2
    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.

    Comment

    • pronerd
      Recognized Expert Contributor
      • Nov 2006
      • 392

      #3
      You want to set the attribute 'className' not class.

      So the line
      Code:
      newDiv.setAttribute('class', 'newDiv');
      Should be

      Code:
      newDiv.className='newDiv';

      Comment

      • poe
        New Member
        • Jun 2007
        • 32

        #4
        Originally posted by pronerd
        You want to set the attribute 'className' not class.

        So the line
        Code:
        newDiv.setAttribute('class', 'newDiv');
        Should be

        Code:
        newDiv.className='newDiv';
        Thanks, that fixed it.

        Comment

        Working...