Is constructing a big DOM object at the beginning of your module considered best practice?


#1

I personally tend to store a string of element selector in my module and then use jQuery selector, e.g.:

var elementStr = "nav#navigation";
$(elementStr).find("ul.menu")

The reason that I prefer storing a string of selector over the DOM object is it allows me to flexibly combine with other strings to form a new selector, such as elementStr+' ul.menu', etc.
But recently I read many other people's code starting like this:

var DOM = {};
var DOM.nav = $("nav#navigation");

My question is if one of the two above considered best practice? and why? Thanks.


#2

google search
== discussions / opinions ==
jquery Is constructing a big DOM object at the beginning of your module considered best practice? site:stackoverflow.com
http://stackoverflow.com/questions/2217409/jquery-best-practice-for-creating-complex-html-fragments
http://stackoverflow.com/questions/759887/how-to-create-a-dom-node-as-an-object

== the Book ==
http://api.jquery.com/jquery/