dominikbulaj
10/21/2016 - 6:53 AM

one-time handling of the click event using vanilla addEventListener() From https://medium.com/dev-channel/once-upon-an-event-listener-f516b

one-time handling of the click event using vanilla addEventListener()

From https://medium.com/dev-channel/once-upon-an-event-listener-f516bca519e6#.e9lx7f787

element.addEventListener('click', function cb(event) {  
  // ...one-time handling of the click event...  
  event.target.removeEventListener(event.type, cb);
});

// or:

element.addEventListener('click', function(event) {
  // ...one-time handling of the click event...
}, {once: true});