I was told that an 'event object' gets passed as a parameter to the function in the program below. What would an example of an 'event object' be? Is it, for example, the <p> element if you clicked on a <p> or <html> if you clicked on <html>, or is the event object the actual 'click'?
document.addEventListener('click', function(e){
console.log(e.target.nodeName);
},false);
Brian Tompsett - 汤莱恩
5,92772 gold badges64 silver badges135 bronze badges
asked Mar 23, 2011 at 5:11
mjmitche
2,0736 gold badges25 silver badges31 bronze badges
2 Answers 2
It's roughly the actual click. See the thorough MDC documentation for event and MouseEvent. You can get the target element from event.target.
answered Mar 23, 2011 at 5:13
Matthew Flaschen
286k53 gold badges525 silver badges554 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Amadan
Also, you can use
console.log(e) to take a peek at what you got.in html code you can use by example:
<input type="text" onchange="show(this)" />
<script>
show(e) {alert(e.value);}
</script>
best regards!
Comments
lang-js