I want to add multiple listeners to my buttons using JavaScript ES6. I am following this guide
For some reason, it is not working for me.
HTML:
<input type="button" value="Button">
JavaScript:
function multipleEventsListeners(elem, events, func) {
events.split().forEach(e => elem.addEventListener(e, func, false));
}
const INPUT = document.querySelector('input');
multipleEventsListeners(INPUT, 'onclick ontouchstart', function(e) {
console.log(this.tagName);
});