Get the App
SLTechnology News&Howtos  ›  Development  › 

How to implement event capture in js

Shulou Source: shulou.com Published: 2022-06-03 08:48:55 11月15日 Update

This article mainly introduces how to achieve event capture in js, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, let the editor take you to understand it.

1. When a mouse clicks or triggers a dom event, the element that triggers the dom event is called the event source.

2. The browser propagates events from the root node = > event source (from outside to inside).

3. The less specific node should receive the event earlier, and the most specific node should receive the event last.

Example

S2 s1.addEventListener ("click", function (e) {console.log ("S1 bubbling event");}, false); s2.addEventListener ("click", function (e) {console.log ("S2 bubbling event");}, false) Thank you for reading this article carefully. I hope the article "how to capture events in js" shared by the editor will be helpful to everyone. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Events articles nodes values elements interests at the same time examples more friends browsers knowledge editing industry information information channels channels mouse communication reference Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Huawei Docker Shulou Tech Info Shulou Information