There is no single right answer to this question. It all depends on what you have to work with. If you are working with a page that has massive amount of elements in the DOM tree, it's better to cache the references and reuse them, to speed up look up time. If you are working on a small page, it's better to look up elements on the fly, and minimize memory consumption of the browser.
It also depends on the browsers you are targeting. For example, newer versions of Firefox take a while to fine an element first time, but they cache the reference internally, so next time you are going to look it up, it's going to be almost instant. IE, on the other hand, doesn't cache lookup values, but it's seek time is much faster than Firefox on the first try.
A lot of modern frameworks will cache the elements that you found for you. However, I, personally still prefer to use document.getElementById most of the time. What I do, when I need to cache lookup values is the following:
function registerElement(id)
{
if (!this["get_" + id])
this["get_" + id] = function() {
var element = document.getElementById(id);
this["get_" + id] = function() {return element;};
return element;
}
}
You use this by calling registerElement and passing it an ID of the element. When you need to retrieve the value, you call get_element id you passed and on the first run it will look up the element and cache it, on every consecutive call it will just return cached value.