<style>
.cl {width:100px; height: 40px; border: 1px solid red;}
#di {border: 1px solid blue;}
</style>
<div id="idd">
<button>add</button>
<div class="cl">1</div>
<div class="cl">2</div>
<div>
<script>
window.onload = function () {
document.getElementById('idd').onclick = function (e) {
e = e || event;
var target = e.target || e.srcElement;
if (target == this.children[0]) {
var el = document.createElement('div');
el.innerHTML = this.children.length - 1;
el.className = 'cl';
this.appendChild(el);
} else
if (target.className == 'cl') {
if(!document.getElementById("di")) {
var el = document.createElement("div");
el.id = "di";
el.innerHTML = "div";
} else {
var el = document.getElementById("di");
}
target.appendChild(el);
}
}
}
</script>