Merging jQuery objects
How to merge jQuery objects for method chaining
When working with jQuery, you sometimes have two or more objects for specific functionality...
$one = $("#one");
$two = $("#two");
$three = $("#three");
But what if you want to call methods on all of them at the same time? Instead of..
$one.show().addClass("myClass");
$two.show().addClass("myClass");
$three.show().addClass("myClass");
You can .add() them together...
$one.add($two).add($three).show().addClass("myClass");
This has the advantage of being non-destructive, so it does not effect the first object (unlike $.merge
)