what i am using right now
window.addEventListener("touchend", myFunction);
window.addEventListener("load", myFunction);
I want to know a way to add it in one line, since OR doesn't work,
window.addEventListener("load"||"touchend", myFunction);
what i am using right now
window.addEventListener("touchend", myFunction);
window.addEventListener("load", myFunction);
I want to know a way to add it in one line, since OR doesn't work,
window.addEventListener("load"||"touchend", myFunction);
According to this https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener it's not allowed
Type
is a case-sensitive string representing the event type to listen for. You can not define multiple conditions in it.
https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Parameters
But you can apply multiple listeners to the same function like this:
function addMultipleListeners(eventNames) {
var events = eventNames.split(' ');
var eventsLength = events.length;
var i;
for (i = 0; i < eventsLength; i++) {
window.addEventListener(events[i], myFunction);
}
}
addMultipleListeners('mousemove touchmove');
I hope, it helps you.