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);
Brian Tompsett - 汤莱恩
5,92772 gold badges64 silver badges135 bronze badges
asked Mar 23, 2011 at 5:11

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.

answered Mar 23, 2011 at 5:13
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!

answered Jun 9, 2014 at 16:32

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.