IE 6/7 javascript class assignment for newly created elements

Discussion in 'Javascript' started by Craig Taylor, Jan 18, 2007.

  1. Craig Taylor

    Craig Taylor Guest

    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
    Craig Taylor, Jan 18, 2007
    #1
    1. Advertising

  2. Craig Taylor wrote:

    > eWin2 = document.createElement( "div");



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


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

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Jan 18, 2007
    #2
    1. Advertising

  3. Craig Taylor

    Craig Taylor Guest

    Martin Honnen wrote:
    > Craig Taylor wrote:
    >
    > > eWin2 = document.createElement( "div");

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

    >
    > Use
    > eWin2.className = 'window';
    > instead of setAttribute.
    >
    > --
    >
    > Martin Honnen
    > http://JavaScript.FAQTs.com/


    That did it - I was looking under Element insteaed of HTMLElement.

    (It's always the little things).

    Thanks again,

    - Craig Taylor
    www.ctalkobt.net
    Craig Taylor, Jan 18, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Earl Teigrob
    Replies:
    0
    Views:
    328
    Earl Teigrob
    Aug 5, 2003
  2. David Lozzi

    Get newly created record's ID??

    David Lozzi, Dec 7, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    402
    Jacco Schalkwijk
    Dec 7, 2004
  3. =?Utf-8?B?bWN3b29x?=

    Error Debubbing newly created ASP.NET Project

    =?Utf-8?B?bWN3b29x?=, Nov 11, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    2,337
    Steven Cheng[MSFT]
    Nov 15, 2005
  4. Replies:
    1
    Views:
    551
    John Timney \( MVP \)
    May 31, 2006
  5. Edward Lorden

    HTTP 403 error on a newly created web site

    Edward Lorden, Jun 2, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    8,918
    Edward Lorden
    Jun 2, 2006
Loading...

Share This Page