Merging jQuery objects
.add()
does exactly what you're after.
h3.add(btn).hide();
If you wanted to make it a little more convenient for yourself, with a "merge" function like in your question, this could be added easily:
$.merge = function(objs) {
var ret = objs.shift();
while (objs.length) {
ret.add(objs.shift());
}
return ret;
};
$.merge([h3, btn]).hide()
$.map
can flatten arrays:
function merge(array_of_jquery_objects) {
return $($.map(array_of_jquery_objects, function(el) {
return el.get();
}));
}
$(btn).add(h3).hide();
Not sure if it works though, documentation for add doesn't mention haivng the jQuery object as a parameter but only a list of elements, so if that doesn't work this should:
$(btn).add(h3.get()).hide();