jQuery same click event for multiple elements
$('.class1, .class2').on('click', some_function);
Or:
$('.class1').add('.class2').on('click', some_function);
This also works with existing objects:
const $class1 = $('.class1');
const $class2 = $('.class2');
$class1.add($class2).on('click', some_function);
I normally use on
instead of click
. It allow me to add more events listeners to a specific function.
$(document).on("click touchend", ".class1, .class2, .class3", function () {
//do stuff
});