Vanilla JS event delegation - dealing with child elements of the target element

前端 未结 2 1709
挽巷
挽巷 2020-11-28 09:35

I\'m trying to do event delegation in vanilla JS. I have a button inside a container like this

2条回答
  •  旧巷少年郎
    2020-11-28 10:11

    Alternate Solution:

    MDN: Pointer events

    Add a class to all nested child elements (.pointer-none)

    .pointer-none {
      pointer-events: none;
    }
    

    Your mark-up becomes

    With the pointer set to none, the click event wouldn't fire on those elements.

    https://css-tricks.com/slightly-careful-sub-elements-clickable-things/

提交回复
热议问题