tags:

views:

55

answers:

2

Hi, If I have following in jQuery $("#someId").add("#someOtherId").bind("click", function(e) {... I get the click bound only to the last element. How can I use add() and bind all elements to some event?

+1  A: 

I don't see why that is a problem, but in this case you should be able to use the following:

$("#someId, #someOtherId").bind("click", function(e) {...

You can add multiple selectors by separating them with a comma.

T B
+3  A: 

Easiest solution?

$("#someId, #someOtherId").click(function(e) { ... });

Multiple selectors can be separated by commas.

Alternate solution? Use andSelf():

$("#someId").add("#someOtherId").andSelf().click(function(e) { ... });
cletus