EventTarget.addEventListener(type
.listener
.options
.useCapture
)
- type
- listener
- option
- useCapture
true
Div > spanfalse
Span > div
document.write(`<body><div id="div">div <span id="span">span</span></div>`);
div.addEventListener('click'.() = >alert('div'))
span.addEventListener('click'.() = >alert('span'))
// "span" -> "div"
div.addEventListener('click'.() = >alert('div'), true)
span.addEventListener('click'.() = >alert('span'), true)
// "div" -> "span"
Copy the code