Gunakan proses yang sama. Anda sudah memiliki variabel iDivyang masih merujuk ke elemen asli yang <div id='block'>Anda buat. Anda hanya perlu membuat yang lain <div>dan menelepon appendChild().
// Your existing code unmodified...
var iDiv = document.createElement('div');
iDiv.id = 'block';
iDiv.className = 'block';
document.getElementsByTagName('body')[0].appendChild(iDiv);
// Now create and append to iDiv
var innerDiv = document.createElement('div');
innerDiv.className = 'block-2';
// The variable iDiv is still good... Just append to it.
iDiv.appendChild(innerDiv);
http://jsfiddle.net/W4Sup/1/
Urutan pembuatan acara tidak harus seperti yang saya miliki di atas. Anda dapat secara bergantian menambahkan yang baru innerDivke div luar sebelum Anda menambahkan keduanya ke <body>.
var iDiv = document.createElement('div');
iDiv.id = 'block';
iDiv.className = 'block';
// Create the inner div before appending to the body
var innerDiv = document.createElement('div');
innerDiv.className = 'block-2';
// The variable iDiv is still good... Just append to it.
iDiv.appendChild(innerDiv);
// Then append the whole thing onto the body
document.getElementsByTagName('body')[0].appendChild(iDiv);
document.body.