28
var _sel1 = $('.red');
var _sel2 = $('.yellow');

How can I merge them into one, without using different selectors?

// I don't want to do it this way 
var _sel3=$('.red,.yellow') or $('.red').add('.yellow');

1 Answer 1

45

Use add():

var _sel3 = _sel1.add(_sel2);
1
  • 1
    okie i got it , i was not aware of the fact that we can pass some variable to ".add()" to add to current selection. it worked thanx. Commented Mar 8, 2010 at 11:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.