jquery - Calling a javascript function from another .js file -
i have 2 external .js files. first contains function. second calls function.
file1.js
$(document).ready(function() { function menuhoverstart(element, topshift, thumbchange) { ... function here ... } }); file2.js
$(document).ready(function() { settimeout(function() { menuhoverstart("#mydiv", "63px", "myimg"); },2000); }); the trouble not running function. need 2 separate files because file2.js inserted dynamically depending on conditions. function works if include settimeout... line @ end of file1.js
any ideas?
the problem is, menuhoverstart not accessible outside of scope (which defined .ready() callback function in file #1). need make function available in global scope (or through object available in global scope):
function menuhoverstart(element, topshift, thumbchange) { // ... } $(document).ready(function() { // ... }); if want menuhoverstart stay in .ready() callback, need add function global object manually (using function expression):
$(document).ready(function() { window.menuhoverstart = function (element, topshift, thumbchange) { // ... }; // ... });
Comments
Post a Comment