currentTarget in events propagation
by podlipensky
HTML
<script type="text/javascript">
function handler(e, currentTarget){
currentTarget = currentTarget || this;
console.log(currentTarget.id);
}
</script>
<div id="foo" _onclick="handler(event, this)">
<div id="bar" _onclick="handler(event, this)"></div>
</div>
CSS
#foo {
background-color: yellow;
width: 200px;
height: 200px;
}
#bar {
background-color: blue;
width: 100px;
height: 100px;
margin: auto;
}
JavaScript
var foo = document.getElementById('foo'),
bar = document.getElementById('bar');
foo.onclick = handler;
bar.onclick = handler;
//bar.addEventListener('click', handler, true);
//foo.addEventListener('click', handler, true);
function handler(){
console.log(this.id);
}