How can I listen to the intermediate element p of div > p > a by using event delegation?

I have looked for it in hundreds of degrees before, and it is basically a two-tier div > p, but now I have more than two layers of demand. I have thought about finding the parent element of ev.target, but if the nesting is a little deeper, it will be very troublesome, and I also consider that if I look for a parent element, the parent element of span is a, and the parent element of an in front is p, so I can"t accurately monitor the event of p. What can I do to solve this problem?.

Sep.16,2021

you can give special identification to the elements you want to listen to. Then at the top level, determine whether there is that flag


you can only add classes if you don't want to find them through complex node relationships | | id then go to class, id, ah, this kind of processing
of course, other attributes can also

if you want to use event delegates, you have to consider a variety of situations:
separately judge that event.target.tagName is "DIV A SPAN", and find the values of parent elements at different levels.

Menu