0

Hello everyone,
I am trying to create html like this

html code

   <div id="windwo">
  <div id="windowhead">
  </div>
  </div>

And this is my try
**Js cose **

   var div = document.createElement('div');
        div.id = 'window';
        var div = document.createElement('div');
        div.id = 'windowhead';
        document.body.appendChild(div);
        document.body.appendChild(div);
2
Contributors
1
Reply
13
Views
2 Years
Discussion Span
Last Post by stbuchok
0

Try this:

var div1 = document.createElement('div');
var div2 = document.createElement('div');

div1.id = 'window';
div2.id = 'windowhead';

div1.appendChild(div2);

document.appendChild(div1);

You need to create two different variables and then append one to the other and the other to the document.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.