[ACCEPTED]-How to combine two jQuery results-jquery

Accepted answer
Score: 237

You can use add();

var $foos = $('.foo');

var $foosAndBars = $foos.add('.bar');


var $allFoosAndBars = $allFoos.add($allBars);


Score: 6

Another solution is to use jQuery.merge() (jQuery > 1.0)

Description: Merge 3 the contents of two arrays together into 2 the first array.

So you could simply use 1 it to merge both result :

var $allFoos = $('.foo');
var $allBars = $('.bar');

var $allFoosAndBars = $.merge($allFoos, $allBars);

More Related questions