Пользовательское событие JS
const eventDetails = {
'id': elemId
}
document.dispatchEvent (
new CustomEvent('myCustomEvent', {'detail': eventDetails})
)
Lively Leopard
const eventDetails = {
'id': elemId
}
document.dispatchEvent (
new CustomEvent('myCustomEvent', {'detail': eventDetails})
)
const btn1 = document.getElementById('btn1');
btn1.addEventListener('boo', function () {
alert('Button1 said Boo');
});
const btn2 = document.getElementById('btn2');
btn2.addEventListener('boo', function () {
alert('Button 2 said Boo');
});
const clickEvent = new Event('boo');
btn1.dispatchEvent(clickEvent);
btn2.dispatchEvent(clickEvent);