Hello everyone in the group,
I wrote a JavaScript snippet to retrieve the elements that I click on. However, when I declare the variable using "var," it only shows the last clicked element as the result. But when I use "let" for declaration, it gives me the desired outcome (retrieving the correct element that I click on).
Below is the image when I declare using "var":
And here is the image when I use "let":
I hope someone can help me clarify why, when declaring with "var," it only prints the last element. Thank you, everyone, for your assistance.
I want to display the element that I click on.