еще один вариант
<div id="container">
<div class="toggle"></div>
<div class="toggle"></div>
<div class="toggle"></div>
</div>
<script>
window.onload = function () {
var container = document.getElementById('container'),
eDivTootgle = container.querySelectorAll('.toggle'),
elLength = eDivTootgle.length,
i = 0,
color;
container.onclick = function (event) {
event = event || window.event;
var e = event.target || event.srcElement;
while (e != this) {
if (e.tagName == 'INPUT') {
color = e.parentNode.style.background;
e.parentNode.style.background = color ? '' : 'red';
break;
}
e = e.parentNode;
}
};
for (; i < elLength; i++) {
eDivTootgle[i].insertAdjacentHTML('afterbegin', '<input type="button" value="Behind"/>');
};
};
</script>