By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,969 Members | 1,705 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,969 IT Pros & Developers. It's quick & easy.

Dynamic Div Problem

P: 3
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:
Expand|Select|Wrap|Line Numbers
  1.       <Html>
  2.       <body>
  3.           <div id="myDiv"></div>
  4.           <input type="Button" onclick="doSMT();" />
  5.       </body>
  6.  
  7.       </Html>
javascript:
Expand|Select|Wrap|Line Numbers
  1.       function doSMT()
  2.        {
  3.        var xx = document.getElementById("myDiv");
  4.        var yy=document.createElement("DIV");
  5.        yy.appendChild(xx);  <== Problem is Here for second run of this function
  6.        }                                     (ie, for second click)
May 15 '09 #1
Share this Question
Share on Google+
5 Replies


acoder
Expert Mod 15k+
P: 16,027
Surely, you mean:
Expand|Select|Wrap|Line Numbers
  1. xx.appendChild(yy);
?
May 15 '09 #2

P: 3
No Sir, the problem is appending a div to a dynamic div.
the code attached is what i mean.
May 15 '09 #3

acoder
Expert Mod 15k+
P: 16,027
You need to append this div to the body:
Expand|Select|Wrap|Line Numbers
  1. document.body.appendChild(yy);
May 15 '09 #4

P: 3
Still my problem remains.
actually i am unable to get the static div after appending it to a dynamic div.
Am i conceptually wrong ?
May 16 '09 #5

Dormilich
Expert Mod 5K+
P: 8,639
do you want to copy the static div into the new one or move it there?
May 17 '09 #6

Post your reply

Sign in to post your reply or Sign up for a free account.