jquery on change on multiple elements 1

jquery on change on multiple elements

$('.class1, .class2').on('click', function () {console.log('TODO...')});

//OR....

var elem1 = $('.class1');
var elem2 = $('.class2');
elem1.add(elem2).on'click', function () {console.log('TODO...')});

Here is what the above code is Doing:
1. We are selecting all elements with class class1 and class2.
2. We are attaching a click event handler to all elements with class class1 and class2.
3. When the user clicks on any of the elements with class class1 or class2, the click event handler will be executed.

Similar Posts