How to addEventListener to multiple elements in a single line

Example 1:

element1.addEventListener("input", function() {
this function does stuff 
});

Example 2:

element1 && element2.addEventListener("input", function() {
this function does stuff
});

It might not be correct grammatically, but is there a way I can give two elements the same event listener at the same time (same line) instead of having to write them apart?

161 thoughts on “How to addEventListener to multiple elements in a single line”

Leave a Comment