JS追加削除Divを実現



<html>
<head>
</head>
<body>
<div id='div1'></div>
<input type = 'button' onclick='addElement()' value='   ~     ~   ~'>    
<input type = 'button' onclick='dropElement()' value=' ,    !!'>    
</body>
<script>
  var i = 1;
  function addElement(){
    var div = document.createElement('div');
    div.style.backgroundColor = 'red';
div.style.fontSize = '100px';
div.innerHTML = '  ~    ~    ~~';
div.id = 'Elem'+i;
document.getElementById('div1').appendChild(div);
i++;
  }
  function dropElement(){
    var aaa = document.getElementById('Elem'+(i-1));
document.getElementById('div1').removeChild(aaa);
i--;
  }
  
</script>
</html>