Try onload() event of javascript. It happens because when you are adding your script inside the .. your script starts working immediately before the web page is even loaded. So to handle this you need to make sure that your script starts working after the page has been completely loaded. And for that write your javascript code or function that you need to make work after complete page load inside window.onload = function(){ //here your code goes };
Update your menu.js file as follows :
javascript : menu.js
window.onload = function(){
// your javascript code goes here...
};
References : onload()