I am working on a project to visualize YouTube channels using its Data API. I am developing the channel view, and I have a section where I show the channel videos. The problem I have is that I want to add an onclick event to the channel video cards, so that when I click, it takes me to another screen to see the video in large. The problem is that I can’t add the listener.
interface
I have been trying many ways to add the click, and I can’t seem to hear the event.
HTML
I’ve realized that it may be because the parent of all the cards (div div_channel_videos_row), has a scroll event that I use to load another 50 videos when I reach the end of the list of 50 videos.
Parent`s scroll event
If I capture the onclick event in that parent div, and I do the following, it works. Possible solution
But I don’t understand why it happens. I can not capture an onclick inside an onscroll? The code I would like to use is the following, but it is the one that does not work for me.
video card onclick listener
Note that the cards are received correctly, the list of HTML elements exists.
cards elements before adding onclick listener
I hope someone can help me. Thank you very much!