It looks like your selectors
object is being defined at a time when the DOM is not ready. When you write $("selector")
in your object like that, the jQuery function is called immediately, and returns an array containing whatever it finds.
I thing that you should do one of two things: Either change your selectors array to contain just the selectors, like this:
selectors : {
div : '#top-slide',
signup : '#top-slide #signup',
login : '#top-slide #login',
signup_trigger : '#header .top-slide-triggers a.signup-trigger',
login_trigger : '#header .top-slide-triggers a.login-trigger',
close : 'a.close'
},
And then when you want to use it, call jQuery at that point:
var selectors = IT.TopSlide.selectors;
$(selectors.div).hide();
or,
Put functions into your selectors
object, which you can call whenever you need to get the current list of matched dom elements:
selectors : {
div : function() { return $('#top-slide') },
signup : function() { return $('#top-slide #signup') },
login : function() { return $('#top-slide #login') },
signup_trigger : function() { return $('#header .top-slide-triggers a.signup-trigger') },
login_trigger : function() { return $('#header .top-slide-triggers a.login-trigger') },
close : function() { return $('a.close') }
},
And then, to use it, do this:
var selectors = IT.TopSlide.selectors;
selectors.div().hide();
Either way will work, and will delay actually calling jQuery until the right point -- when you actually want to match what's in the DOM.
Update
If you need to have these functions cached at the time that the document is first loaded, then you will need to have the jQuery function called in a $(document).ready() callback. You can keep the code in your namespace by having a function that calls jQuery and caches all of the results, like this:
IT.TopSlide = {
...
cacheSelectors: function() {
return {
div : $('#top-slide'),
signup : $('#top-slide #signup'),
login : $('#top-slide #login'),
signup_trigger : $('#header .top-slide-triggers a.signup-trigger'),
login_trigger : $('#header .top-slide-triggers a.login-trigger'),
close : $('a.close')
}
},
...
}
and then,
$(document).ready(function() {
...
IT.TopSlide.selectors = IT.TopSlide.cacheSelectors();
...
}
That way, you have a version cached at the time that the document is loaded and ready, and you have the flexibility of being able to call cacheSelectors() at any other point (say, after you know that the DOM has been modified) and use a new copy, if you need to.