mjmitche
mjmitche

Reputation: 2067

JavaScript event object?

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);

Upvotes: 4

Views: 6850

Answers (2)

user3723128
user3723128

Reputation: 1

in html code you can use by example:

<input type="text" onchange="show(this)" />

<script>
  show(e) {alert(e.value);}
</script>

best regards!

Upvotes: 0

Matthew Flaschen
Matthew Flaschen

Reputation: 285047

It's roughly the actual click. See the thorough MDC documentation for event and MouseEvent. You can get the target element from event.target.

Upvotes: 4

Related Questions