0

Say I want to do this:

document.onclick = () => {
    if (target && target.matches('[data-toggle-modal]')) {
        showModal();
    }
}

And then in another JS file:

document.onclick = () => {
    console.log('test');
}

How can this be done?

Matt
  • 53
  • 4
  • 3
    Never use `onclick`, or any of the other `onX` event properties, mostly for this reason; ie. you can't assign multiple events. Use `addEventListener()` instead – Rory McCrossan Sep 26 '22 at 13:09
  • 1
    `document.onclick` is deprecated use `addEventListener` https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener – Chris G Sep 26 '22 at 13:10
  • Thank you - I have learned something new! – Matt Sep 26 '22 at 13:11

0 Answers0