createElement problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sg_maat@micro-mas.nl

    #1

    createElement problem

    I have a little problem with createElement(a nd msie).

    I was experimenting a bit with createElement and made the following
    script:
    <script>
    var tmp = document.create Element("div");
    tmp.setAttribut e("name", "tmpdiv2");
    tmp.setAttribut e("id", "calendar") ;
    var image = document.create Element("img");
    image.setAttrib ute("src", "img/ok.gif");
    tmp.appendChild (image);

    document.getEle mentById("body" ).appendChild(t mp);
    </script>

    Now this script works fine in msie, netscape, mozilla, firefox and
    opera.

    Then i made the following script:
    //create new element div
    var tmp = document.create Element("div");
    tmp.setAttribut e("name", "tmpdiv");
    tmp.setAttribut e("id", "calendar") ;

    var table = document.create Element("table" );
    table.setAttrib ute("border", "1");
    var tr1 = document.create Element("tr");
    var td1 = document.create Element("td");
    var text = document.create TextNode("Test Text");

    td1.appendChild (text);
    tr1.appendChild (td1);
    table.appendChi ld(tr1);
    tmp.appendChild (table);

    document.getEle mentById("body" ).appendChild(t mp);
    </script>

    But this script show notthing in msie(other browser work fine). And my
    question really is why???

    Stephan Maat

  • kaeli

    #2
    Re: createElement problem

    In article <1109962483.029 961.324760@g14g 2000cwa.googleg roups.com>,
    sg_maat@micro-mas.nl enlightened us with...[color=blue]
    >
    > var table = document.create Element("table" );
    > table.setAttrib ute("border", "1");
    > var tr1 = document.create Element("tr");
    > var td1 = document.create Element("td");
    > var text = document.create TextNode("Test Text");
    >
    > td1.appendChild (text);
    > tr1.appendChild (td1);
    > table.appendChi ld(tr1);[/color]

    This worked for me:
    (note: document.body, not document.getEle mentById("body" ) and the addition of
    tbody in the table)

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title> New Document </title>
    </head>

    <body>
    <script>
    var tmp = document.create Element("div");
    tmp.setAttribut e("name", "tmpdiv");
    tmp.setAttribut e("id", "calendar") ;

    var table = document.create Element("table" );
    table.setAttrib ute("border", "1");
    var tbody = document.create Element("tbody" );
    var tr1 = document.create Element("tr");
    var td1 = document.create Element("td");
    var text = document.create TextNode("Test Text");

    td1.appendChild (text);
    tr1.appendChild (td1);
    tbody.appendChi ld(tr1);
    table.appendChi ld(tbody);
    tmp.appendChild (table);

    document.body.a ppendChild(tmp) ;
    </script>
    </body>
    </html>


    --
    --
    ~kaeli~
    Experience is something you don't get until just after you
    need it.



    Comment

    • sg_maat@micro-mas.nl

      #3
      Re: createElement problem

      thanks,

      including a tbody did the trick.
      And both document.body and document.getEle mentById("body" ) work for
      appendChild().

      Is there a reason why msie needs a tbody and opera, netscape, mozilla
      and firefox don't???

      Stephan Maat

      Comment

      • RobB

        #4
        Re: createElement problem

        sg_maat@micro-mas.nl wrote:[color=blue]
        > thanks,
        >
        > including a tbody did the trick.
        > And both document.body and document.getEle mentById("body" ) work for
        > appendChild().
        >
        > Is there a reason why msie needs a tbody and opera, netscape, mozilla
        > and firefox don't???
        >
        > Stephan Maat[/color]

        <URL:
        http://groups-beta.google.com/group/...a46452ae84eaa9[color=blue]
        >[/color]

        Comment

        • kaeli

          #5
          Re: createElement problem

          In article <1109966472.494 435.316520@g14g 2000cwa.googleg roups.com>,
          sg_maat@micro-mas.nl enlightened us with...
          [color=blue]
          >
          > including a tbody did the trick.
          > And both document.body and document.getEle mentById("body" ) work for
          > appendChild().[/color]

          I had problems with document.getEle mentById("body" ) for some odd reason.
          I often have problems for odd reasons. *grins*
          [color=blue]
          >
          > Is there a reason why msie needs a tbody and opera, netscape, mozilla
          > and firefox don't???
          >[/color]

          MSIE sucks ass? ;)

          --
          --
          ~kaeli~
          When two egotists meet, it's an I for an I.



          Comment

          Working...