Asim Zaidi
Asim Zaidi

Reputation: 28284

Check if one of two elements are clicked

I am checking if one button is clicked like this

$j('#Button1').click( function () { 

and then performing a function but now I want to perform the same function when either Button1 or Button2 is clicked.

What is the jQuery syntax for that?

Upvotes: 1

Views: 1829

Answers (2)

Steve Wellens
Steve Wellens

Reputation: 20620

Another option is to use a wild card selector:

$('input[id^=Button]').click( function () { 

Matches Button1, Button2, Button99, etc.

Upvotes: 2

Naftali
Naftali

Reputation: 146310

you can do this:

$j('#Button1, #Button2').click( function () { 

Upvotes: 11

Related Questions