jquery selector variable with event -


this question has answer here:

i'm having trouble selector variable jquery event.

when store 2 or 3 jquery objects variables, how can write code in same event function using them without repeating same line ? may sound confusing have @ example , it.

i can write

$("#a, #b").click( function(){   // stuff } ); 

but when store them this:

var = $("#a"), b = $("#b"); 

and wanna assign each of them click event.

// works long

a.click(function(){});  b.click(function(){}); 

// want have like

(a + b).click(function(){}); 

don't know if possible in jquery, if so, please me in advance

this jsfiddle link i've tested, http://jsfiddle.net/umeaw/

you can use .add

a.add(b).click(function(){}); 

Comments