Target on click
- by 2x2p1p
Hi guys.
Look this code:
<div>
<a href = "#"><span>Click me MAN !</span></a>
</div>
<script type = "text/javascript">
window.onload = function () {
document.body.addEventListener ("click", function (event) {
var target = event.target;
alert ("Returns \"" + target.nodeName + "\". Just want \"" + target.parentNode.nodeName + "\"")
}, false);
}
</script>
You can see the element "span" inside a "link", when the "link" is clicked the current target is the same "span". How can the "event.target" return "link" instead of "span".
Thanks and no, I don't want to use "parentNode".