<script>function live (eventType, elementId, cb) {
document.addEventListener(eventType, function (event) {
var el = event.target, found;
while (el && !(found = el.id === elementId)) {
el = el.parentElement;
}
if (found) {
cb.call(el, event);
}
});
}
live("click", "test", function (event) {
alert(this.id);
});
setTimeout(function() {
var div = document.createElement('div');
div.id = 'test';
div.innerHTML = 'click me';
document.body.appendChild(div);
}, 500)</script>