domEventPromise.js 354 B

1234567891011
  1. const domEventPromise = (element, eventName) => {
  2. return new Promise((resolve, reject) => {
  3. const handler = event => {
  4. resolve(event);
  5. element.removeEventListener(eventName, handler);
  6. }
  7. element.addEventListener(eventName, handler);
  8. });
  9. }
  10. domEventPromise(button, 'click').then( e => console.log('event click happens', e))