Dynamic Div Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kallol05
    New Member
    • May 2009
    • 3

    Dynamic Div Problem

    Hi all,
    I have a prob regarding javascript.
    I have a Div in my web page, Now i get that div by getElementById( "myDiv") and
    append it to a dynamic Div created in the javascript file by appendChild(xx) . This works fine for the first time.
    But from the next time it will loose the Div in the page and showing null. WHY ??

    My code :
    Html Page:
    Code:
          <Html>
          <body>
              <div id="myDiv"></div>
              <input type="Button" onclick="doSMT();" />
          </body>
          
          </Html>
    JavaScript:
    Code:
          function doSMT()
           {
           var xx = document.getElementById("myDiv");
           var yy=document.createElement("DIV");
           yy.appendChild(xx);  <== Problem is Here for second run of this function
           }                                     (ie, for second click)
    Last edited by acoder; May 15 '09, 02:11 PM. Reason: Added [code] tags
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Surely, you mean:
    Code:
    xx.appendChild(yy);
    ?

    Comment

    • kallol05
      New Member
      • May 2009
      • 3

      #3
      No Sir, the problem is appending a div to a dynamic div.
      the code attached is what i mean.

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        You need to append this div to the body:
        Code:
        document.body.appendChild(yy);

        Comment

        • kallol05
          New Member
          • May 2009
          • 3

          #5
          Still my problem remains.
          actually i am unable to get the static div after appending it to a dynamic div.
          Am i conceptually wrong ?
          Last edited by kallol05; May 16 '09, 11:14 AM. Reason: reply to ur post

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            do you want to copy the static div into the new one or move it there?

            Comment

            Working...