Hi, I have a question more about how to structure my code when using JQuery. I have this master HTML template that contains my site header and footer and in between is the dynamic area or page layout area. This area contains my main user interface.
Currently in this master template I have something like this. <html> <head> <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script> <script type="text/javascript" src="js/app.js"></script> </head> <body> <!-- Common Header --> <!-- Dynamic area here / Page Layout essentially --> <!-- Common Footer --> </body> </html> Within app.js I define: $(document).ready(function(){ // code to execute when the document is loaded...... }); This does work, but say in my ready() function call there is an element on the page that isn't being displayed and I try to reference it? I presume I will get an error My concern is by including app.js in the master template there is a good chance it may reference divs, tables, or whatever that don't exist because they are not part of the page that the user is on. Since the master template is the only HTML file I have, it's the only file that actually has a <head></head> section so that is why I'm putting: <script type="text/javascript" src="js/app.js"></script>, in the head section Since my page layout can be different depending on which page I'm on, there is a chance that any code I define in app.js may try to reference divs or something that aren't part of the page layout. So does it make more sense to include the relevant javascript file with the page layout? If I do it, then <script type="text/javascript" src="js/app.js"></script> will not be in the head tag, but would appear within the <body> tag. Hope that makes sense. Any help appreciated -Westside