create and append div to body tag

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved

Join Date: Jun 2004
Posts: 247
Reputation: cmills83 is an unknown quantity at this point 
Solved Threads: 1
cmills83 cmills83 is offline Offline
Posting Whiz in Training

create and append div to body tag

 
0
  #1
Nov 8th, 2008
i have tried a few tutorials but i cant get this working. I am trying to create a div with the id of overlay and insert it right after the body tag when a function is run. can anyone help? thanks
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,652
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 474
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: create and append div to body tag

 
0
  #2
Nov 11th, 2008
Google for createElement and insertBefore.
I don't accept change; I don't deserve to live.

Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 954
Reputation: essential will become famous soon enough essential will become famous soon enough 
Solved Threads: 131
Featured Poster
essential's Avatar
essential essential is offline Offline
Posting Shark

Re: create and append div to body tag

 
0
  #3
Nov 11th, 2008
Here's a simple demo, to get you started!

  1. <html>
  2. <head>
  3. <title><!--Sample--></title>
  4. <script language="JavaScript"type="text/javascript">
  5. <!--
  6. function createDiv()
  7. { var _body = document.getElementsByTagName('body') [0];
  8. var _div = document.createElement('div');
  9. var _text = document.createTextNode('Creating Div Element')
  10. _div.appendChild(_text);
  11. _body.appendChild(_div);
  12. }
  13. window.onload = createDiv;
  14. -->
  15. </script>
  16. </head>
  17. <body>
  18. </body>
  19. </html>

If you need something else just let me know. Good day to you...
Last edited by essential; Nov 11th, 2008 at 1:18 pm.
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 247
Reputation: cmills83 is an unknown quantity at this point 
Solved Threads: 1
cmills83 cmills83 is offline Offline
Posting Whiz in Training

Re: create and append div to body tag

 
0
  #4
Nov 11th, 2008
thanks for the replies i ended up doing this

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function createDivs() {
  2. var div = document.createElement('div');
  3. var container = document.createElement('div');
  4. div.id = 'overlay';
  5. container.id = 'form_container';
  6. if (document.body.firstChild){
  7. document.body.insertBefore(div, document.body.firstChild);
  8. document.body.insertBefore(container, document.body.firstChild);
  9. } else {
  10. document.body.appendChild(div);
  11. document.body.appendChild(container);
  12. }
  13. }
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the JavaScript / DHTML / AJAX Forum


Views: 5169 | Replies: 3
Thread Tools Search this Thread



Tag cloud for JavaScript / DHTML / AJAX
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC