The essence of the task is such, in the middle of the page there will be a div block in which buttons should appear with absolute positioning. Such a problem, I can not put the generated DOM elements in this very div block. It is necessary that the script-generated elements fit into <div id="menu222"></div>

html

  <input type="button" onclick="NewTeg()" value="Добавить кнопку"> <div id="menu222"> </div> 

Js

 function NewTeg() { var d=document.createElement('div'); NUM = (!self.NUM) ? 1 : ++NUM; d.style.textAlign = "center"; d.style.padding = "8px"; d.style.color = "#fff"; d.style.borderRadius ='5px'; d.style.background='#6492cb'; d.style.position='absolute'; d.id ="Dialog" + NUM; d.className = ('drag'); d.innerHTML = NUM; document.body.appendChild(d); } 
  • I do not quite understand, you get to add items, but it does not work specifically in menu222 div? - Vadim Leshkevich
  • I study, and there was such a question - Pavel

1 answer 1

You add this line to the body :
document.body.appendChild(d); but you need to select your div
var box = document.getElementById('menu222') , and for it to add your items
box.appendChild(d);