For example, will the first piece of code perform a full search twice, or is it smart enough to cache results if no DOM changes have occurred?
if ($(\"#navba
There is a nice plugin out there called jQache that does exactly that. After installing the plugin, I usually do this:
var $$ = $.q;
And then just
$$("#navbar .heading").hide();
The best part of all this is that you can also flush your cache when needed if you're doing dynamic stuff, for example:
$$("#navbar .heading", true).hide(); // flushes the cache and hides the new ( freshly found ) #navbar .heading
And
$$.clear(); // Clears the cache completely