LearnFrenzy
Sign in Take a free test

DOM Manipulation · Predict the Output · Question 10

target and currentTarget Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 10 Back to Exercise

The page contains this HTML:

<ul id="menu">
  <li>Home</li>
  <li>Courses</li>
</ul>

What does the following JavaScript code print when it runs on this page?

main.js
const menu = document.getElementById("menu");
menu.addEventListener("click", (e) => {
  console.log(e.target.tagName, e.currentTarget.tagName, e.target.textContent);
});
menu.children[1].click();
  • A UL UL Courses
  • B LI LI Courses
  • C UL LI Home
  • D LI UL Courses Correct
Correct Answer: Option D

target is the clicked li; currentTarget is the ul whose listener is running. tagName is upper-case in HTML documents.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links