var first = $('#one, #two, #three');
var second = $('#six, #seven, #eight');
Now, I wanted to use $.merge() to merge the selections and hide them.
var merged = $.merge(first, second);
merged.hide(); // works, but alters "first"
Since I later have to reuse the first selection separately, I tried copy-merge.
var merged = $.merge( $.merge([], first), second );
merged.hide(); // =
// = Uncaught TypeError: Object [object HTMLDivElement], [object HTMLDivElement], [,...] has no method 'hide'
The error is obvious – elements have lost jQuery association.
- Have I skipped a lesson about selection grouping / merging?
- Is
$(merged).hide();the only solution? - Why did copy-merge drop the jQuery?
You don’t need the
.merge(), use .add() instead: