I'm new to jQuery and javascript. I'm trying out a few things here so let me explain what i have:
-I have several seperate .js files running code. I cannot get them to load BEFORE the code in index.html file fires. It always loads the jQuery file (which sets the window property) and then loads index.html, and THEN all the other .js files i have list with the jQuery main file. So I'm trying to work around this.
I have seperated my javascript into seperate files:
-jQuery.js
(mini) //from any local or main ajax source this works
-mainpage.js
//javascript code for the main page setup. its there for as needed elements, currently-nothing.
-mainmenu.js
//this loads mainmenu.html which conatains the mainmenu list.
-index.html
//The only code i want to run on this is to declare ".active"
class to the home button. I want it in this file so i can use the same universal mainmenu.js and mainmenu.html in all my files.
These are all declared in index.html
's head.
My problem is it loads jQuery.js
loads and then it fires index.html's javascript immediately. I connot figure out how to declare the function that will set #home
button as ".active"
Can i declare it to the document level? i know i shouldnt make it global... but i dnt even know how to do that?
i'm currently do this:
defineactive(){
$(mmlist).find("#home").addClass("active");
}
however, mmlist
hasn't been defined yet. That gets declared in mainmenu.js
, which is loaded AFTER index.html
So i guess my question is Can I declare a function to make able to be called on outside the jQuery.js
?
If not, besides using an outside source/app how can i make sure the javascript files are loaded in order? I plan on using this idea in more complex ways later so I need this to work.