Difference between e.target and e.currentTarget

后端 未结 10 1041
谎友^
谎友^ 2020-11-22 06:29

I don\'t understand the difference, they both seem the same but I guess they are not.

Any examples of when to use one or the other would be appreciated.

10条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-22 06:41

    • e.target is element, which you f.e. click
    • e.currentTarget is element with added event listener.

    If you click on child element of button, its better to use currentTarget to detect buttons attributes, in CH its sometimes problem to use e.target.

提交回复
热议问题