Possible Duplicate:
Merging jQuery objects
** The goal is performance. The duplicate question addresses the function, but I don't believe adds performance value and doesn't address that aspect. **
I want to chain several jQuery elements, for the sake of performance, but for optimization sake they're already cached in variables.
so if I have
$elem1 = $('div#elem1');
$elem2 = $('div#elem2');
$elem3 = $('div#elem3');
This doesn't work so well:
$elem1,$elem2,$elem3.hide();
Is there any way to do that, chaining with already cached elements?
Thanks!
[Edits]
Ok, I really need to clarify. My goal for chaining is performance, with the bonus of concise yet clear code.
$('div#elem1, div#elem2, div#elem3').hide();
defeats the point as it's no longer using the cached vars, but accessing the dom again. Accessing the dom is expensive, so i'm pretty sure it's slower than the 3 lines.
.add() and .merge(), I'm assuming are more expensive than seperating the operation on three lines. For performance sake, until I have time to jPerf, I'll assume 3 different lines rather than extra operations has the best performance.
Thanks for the collaboration, brainstorming, and thoughts, I do appreciate it. I wasn't aware of the possibilities and wouldn't have known what to test on jPerf otherwise.