You must save functions like
fnc = function() { ... };
or any other declaration. Because if you write all this down, this code will only start executing when the entire DOM is loaded. Otherwise, it starts executing immediately after loading it. The jQuery wrapper should only be present when your javascript requires the DOM to load.
var blah = function() {
source share