Skip to content
Advertisement

Array from filter click

I have a list of elements, I want to get on click only the one that I clicked on.I tried to do it this way

JavaScript
JavaScript

But now I get all elements

enter image description here

Advertisement

Answer

Use event.target or event.currentTarget to get the element that is clicked. The difference is that event.currentTarget will always return the element which we have bound the click event listener to, while event.target may refer to descendants inside the clicked element.

In your case, since the <a> tags have no descendants, event.target or event.currentTarget will always yield the same element, and it shouldn’t matter which one you use.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement