SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2002
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    can't center div created by createElement?

    Hi All,

    I have a simple html file, header, couple tagss, etc.
    Code:
    <HTML><HEAD><TITLE>Whatever</TITLE>
    
    <script language="javascript" src="imgal_files/slideie.js"></script>
    
    <BODY onload=BuildOpData()>
    <CENTER><A id = jango name=HomePt></A>
    <P></P><br><br>
    ttttttttttttttttttttttttttt
    <br><br>
    </BODY></HTML>
    BuildOpData inserts a div by calling createElement first and then appending it to the body.

    Code:
    var oDiv = document.createElement("div");
    oDiv.align="center";
    document.body.appendChild(oDiv);
    the first tag in the body is <center>, so I was expecting this div to be centered as well. If I insert the same div in the html file it is centered. The style I am applying to the div should be ok, works for html code at least... Only for DOM I am having this problem.

    Here's the style just in case:
    Code:
    .opMainDiv{width:600px;text-align:left;padding:1px;font-size:9pt;background:#777;color:#fff;border:ridge #fff 1px;margin:0 0 1em 0}
    Any ideas what am I missing here? It's the same for mozilla 1.2.1 and IE 6, divs go to the left instead of the center.
    Have Fun,
    Gator
    zknives.com

  2. #2
    SitePoint Enthusiast
    Join Date
    May 2002
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile Resolved

    In case anyone was interested.
    Browswers were adding closing </center> before the new div was inserted.
    Solution one was to append the div to the center tag itself. Or alternatively create one more div in HTML and append the new div to that.
    Have Fun,
    Gator
    zknives.com


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •