Predict Event Target
Predict Output Medium
Question
When clicking the inner <span>, what is event.target?
Code
<div id="outer">
<span id="inner">Click me</span>
</div>
<script>
document.getElementById("outer").addEventListener("click", (e) => {
console.log(e.target.id);
});
</script>
Hint
event.target is the element that was actually clicked.
Explanation
event.target is the deepest element that triggered the event — the one actually clicked. Even though the listener is on #outer, clicking the #inner span means event.target is the span, so e.target.id is 'inner'. event.currentTarget would be 'outer' (where the listener is attached).
Related Resources
Related Lessons
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.