Problems with native JS event delegation

<ul>
      <li><img src="img/remind.png" alt=""></li>
      <li><img src="img/remind.png" alt=""></li>
      <li><img src="img/remind.png" alt=""></li>
  </ul>

I click on the event to bind to ul, want to delegate to li, and then judge by whether the tagName of e.target is LI. The problem is that li also contains other elements. For example, there is a picture in my li. When clicked, its e.target is img, so the event will not be executed. How can the event be accurately delegated to li? img is just an example, or li will have a more complex structure. At this time, how to avoid the child elements in li to delegate?
A stupid way I used before is to give li a fully covered pseudo element, but I don"t think that"s a good idea

Apr.25,2022

idea:
1, add class (news-item) to the li to be bound, add class (news)
2 to ul, determine whether the class contains news-item by target, if not, find the parent through target, and so on until li.news-item is found or ul.news stops
3, if li.news-item is not found, the event


is not executed.

it must be judged.

  

e.path.find consider?
browser compatibility may be required and has not been studied.

Menu