Forum Moderators: open

Message Too Old, No Replies

Apending to the body

         

bleak26

11:29 am on Mar 14, 2007 (gmt 0)

10+ Year Member



Plese could u tell me how to attach the newly created div tag to the body using the dom, so as to make it appear on the page.

Thank you for your help.

var newdiv = document.createElement('div');

var divIdName = 'newdivnbyme';

newdiv.setAttribute('id',divIdName);

Fotiman

2:56 pm on Mar 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



var newdiv = document.createElement('div');
var divIdName = 'newdivnbyme';
newdiv.setAttribute('id',divIdName);
document.body.appendChild(newdiv);

[edit]:
or for the more pure DOM method approach:

var newdiv = document.createElement('div');
var divIdName = 'newdivnbyme';
newdiv.setAttribute('id',divIdName);
document.getElementsByTagName("body")[0].appendChild(newdiv);

[edited by: Fotiman at 3:23 pm (utc) on Mar. 14, 2007]