The jQuery merge() method together merges the content of two arrays into the first array. This method returns the merged array. The merge() method forms an array containing the elements of both arrays. If we require the first array, we should copy it before calling the merge() method.
It is possible to run jQuery and JavaScript together in you application. All you need to know is, which is a JavaScript Object when trying to run some methods of it. jQuery can be handy sometimes. But, yes!
You can specify any number of selectors to combine into a single result. This multiple expression combinator is an efficient way to select disparate elements. The order of the DOM elements in the returned jQuery object may not be identical, as they will be in document order.
You can use add();
var $foos = $('.foo');
var $foosAndBars = $foos.add('.bar');
or
var $allFoosAndBars = $allFoos.add($allBars);
Another solution is to use jQuery.merge() (jQuery > 1.0)
Description: Merge the contents of two arrays together into the first array.
So you could simply use it to merge both result :
var $allFoos = $('.foo');
var $allBars = $('.bar');
var $allFoosAndBars = $.merge($allFoos, $allBars);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With