Caching a jQuery object "globally" or any other way will help if the
object is:

 - expensive to build, e.g., a large DOM, sprinkled with many objects
as was the case with my 250 questions

 - reusable, e.g., a user can click to "hide all", "show all".

Instead of recalculating the object, I save it in a global variable.
I't isn't messy...

var objAll
function toggleAll() {
  objAll = objAll || $('div.myclass'); // This will do the $
calculation only once and save it globally
  objAll.toggle();
}

Reply via email to