4

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

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

1 Comment

Also, you can use console.log(e) to take a peek at what you got.
0

in html code you can use by example:

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

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

best regards!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.