You can use an array as the argument to $() and it will create a new collection of everything in it. It doesn't hit the DOM again.
$([a, b]).on("click", function() {
...
});
However, it requires that the array contain DOM elements, not jQuery objects. You can turn a jQuery collection into an array of the elements with .get(). Since you'll get nested arrays, you can then use .flat() to flatten this. For ID selectors this isn't really needed, since you could just select the first element with .get(0), but the method below generalizes to collections of multiple elements.
var a = $('#foo');
var b = $('#bar');
$([a.get(), b.get()].flat()).on("click", function() {
alert('Does this work?');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="foo"> Foo </button>
<button id="bar"> Bar </button>